12小时前小编发现微信小程序用户:【Jesse】提出了一个关于“qq小程序代理微信支付时报错,求解答?”的问题,在问题中开发者Jesse对该问题做了如下阐述:
直接请求微信H5下单成功,再此基础上通过qq小程序代理请求微信H5下单时,报错 401 Unauthorized。
代码如下:
//获取商户API私钥
merchantPrivateKey = PemUtil.loadPrivateKey(
new FileInputStream(privateKeyLocation));//自动更新证书
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
new WechatPay2Credentials(h5OrderReq.getMchid(), new PrivateKeySigner(serialNumber, merchantPrivateKey)),
privateKey.getBytes(“utf-8”));
WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
.withMerchant(h5OrderReq.getMchid(),serialNumber,merchantPrivateKey)
.withValidator(new WechatPay2Validator(verifier));//通过WechatPayHttpClientBuilder构造的HttpClient,会自动的处理签名和验签,并进行证书自动更新
HttpClient httpClient = builder.build();h5OrderReq.setNotify_url(h5OrderReq.getNotify_url()+h5OrderReq.getOut_trade_no());
String accessToken = getAccessToken();
//直连微信
//HttpPost httpPost = new HttpPost(“https://api.mch.weixin.qq.com/v3/pay/transactions/h5”);
//qq代理
HttpPost httpPost = new HttpPost(“https://api.q.qq.com/wxpay/v3/pay/transactions/h5?appid=” + appId + “&access_token=” + accessToken);
httpPost.addHeader(“Accept”, “application/json”);
httpPost.addHeader(“Content-type”,“application/json; charset=utf-8”);ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writeValue(bos, h5OrderReq);httpPost.setEntity(new StringEntity(bos.toString(“utf-8”),“utf-8”));
HttpResponse response = httpClient.execute(httpPost);String stringResult = EntityUtils.toString(response.getEntity());
h5OrderRes.setH5_url(stringResult);
注:以上是微信小程序开发者:”Jesse”对于本问题的一些阐述,这里做一个引用,我们将实时关注微信小程序助手对该问题提出的解决方案。
【43分钟前】微信小程序技术运营专员对用户Jesse提出的qq小程序代理微信支付时报错,求解答?给予如下回复
走错片场了吧Σ(⊙▽⊙”a
微信官方小程序的优势是,其用户体验可以最大限度的接近Native App。因此,微信官方智能小程序也把用户体验作为一个核心进行了优化
如果您也在使用微信小程序,请关注我们,如果您有关于微信小程序的使用问题请关注我们,如果您要找百度小程序模板、微信小程序模板请关注小程序模板网或者去微信开放社区找官方人员给予解决,相信微信官方在小程序上的发力会是一个里程碑!