如何初始化微信服务商模式Client
rickycoder opened this issue · comments
wechat.NewClientV3是否可以直传 appId和mchid,官方的例子只需要appId和 mchid
// NewClientV3 初始化微信客户端 v3
// mchid:商户ID 或者服务商模式的 sp_mchid
// serialNo:商户证书的证书序列号
// apiV3Key:apiV3Key,商户平台获取
// privateKey:私钥 apiclient_key.pem 读取后的内容
client, err = wechat.NewClientV3(MchId, SerialNo, APIv3Key, PrivateKey)
官方例子
https://pay.weixin.qq.com/docs/partner/products/partner-jsapi-payment/development.html
//请求URL
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi");
// 请求body参数
String reqdata = "{"
+ ""amount": {"
+ ""total": 100,"
+ ""currency": "CNY""
+ "},"
+ ""mchid": "1900006891","
+ ""description": "Image形象店-深圳腾大-QQ公仔","
+ ""notify_url": "https://www.weixin.qq.com/wxpay/pay.php\","
+ ""payer": {"
+ ""openid": "o4GgauE1lgaPsLabrYvqhVg7O8yA"" + "},"
+ ""out_trade_no": "1217752501201407033233388881","
+ ""goods_tag": "WXG","
+ ""appid": "wxdace645e0bc2c424"" + "}";
StringEntity entity = new StringEntity(reqdata,"utf-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
//完成签名并执行请求
CloseableHttpResponse response = httpClient.execute(httpPost);