代码示例

# 代码示例

  • 代码示例仅供参考

import com.google.gson.JsonObject;
public class BalanceQuery {
    // 测试账号
    private static final String MCH_NO = "PHOT000001";  // 商户号
    private static final String PLAT_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2JoMfFqLsSJjAiCahEnlP3aRj8yCT+WHzR+VvPBTw9S1i7iYWb+MY09CG/HYuHF4+IxshXDJygmndxKf/esuwPybS8mAd//yubHpmZsmBqg1FffT8VH1APa6ZRWASUp4U01ZrbCCp35QA8FuWrJGMJxGx4xk7KUtV2yujxC8noQIDAQAB";  // 平台公钥
    private static final String MCH_PRIVATE_KEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAJU8gKFKD0luIYx7X8+**************************/9FTGN0vA+9ZPC2cwHtNxI2kXf3Vp";  // 商户私钥
    private static final String orderQueryUrl = "https://ph-openapi.toppayment.com/ph/balance/v1";

    public static void main(String[] args) throws Exception {
        query();
    }
    private static void query() throws Exception {
        Map<String, Object> requestParams = new TreeMap<>();
        requestParams.put("mchNo", MCH_NO);
        requestParams.put("currency", "PHP"); // 币种(PHP)
        requestParams.put("timestamp", Long.valueOf(System.currentTimeMillis()));

        StringBuilder stringBuilder = new StringBuilder();
        for (String key : requestParams.keySet()) {
            stringBuilder.append(requestParams.get(key));  // 拼接参数
        }

        String keyStr = stringBuilder.toString();  // 得到待加密的字符串
        System.out.println("keyStr:" + keyStr);
        String signedStr = RequestUtil.privateEncrypt(keyStr, RequestUtil.getPrivateKey(MCH_PRIVATE_KEY));  // 私钥加密
        requestParams.put("sign", signedStr);

        String postJson = new Gson().toJson(requestParams);
        System.out.println("Post Json Params:" + postJson);

        String responseJson = RequestUtil.doPost(orderQueryUrl, postJson);  // 发送 post json请求
        System.out.println("Response Msg:" + responseJson);
    }
}

暂无示例