**我是在微信公众号里,打开了H5网页进行支付**
**公众号里面的网页授权地址已填好
微信商户JSAPI支付目录下地址也已经填好**
**1:能正常获得code,**
**2:能正常获得 openid**
**3:签名, 签名用的是商户的秘钥,不是公众号的秘钥,**
-------- 开始签名------------------
function getSign(keys,params){
let str = ''
for(let i=0;i<keys.length;i++){
const key = keys[i]
str += key + '=' + params[key] + '&';
}
str = str + 'key=' + mchsecret // 这里用的是商户的秘钥,不是公众号的秘钥,不知道对不对
const tempStr = encodeURI(str); //url 编码
const md5 = crypto.createHash('md5') //md5加密
let md5str = md5.update(tempStr).digest('hex').toUpperCase();
return md5str;
}
这里是正常的没有问题。
---------签名结束------------------------------------------------------------------
4:签名完名以后完转xml,这里重要数据我都用xxx 来代替了
<xml>
<appid><![CDATA[xxxxxxxxxxxxx]]></appid>
<attach>深圳分店</attach>
<body>这是一个测试</body>
<device_info>WEB</device_info>
<mch_id>0000000000000</mch_id>
<nonce_str>p@xdtestabc123d</nonce_str>
<notify_url>xxxxxxxxxxxxx</notify_url>
<openid>xxxxxxxxxxxxxxxxxxx</openid>
<out_trade_no>1001001</out_trade_no>
<spbill_create_ip>198.61.17.12</spbill_create_ip>
<total_fee>1</total_fee>
<trade_type>MWEB</trade_type>
<sign>56AEFE5236B1B481F660896D08910F12</sign>
</xml>
5: -------- 开始下单----------------------------------
const unifiedorder_url = "https://api.mch.weixin.qq.com/pay/unifiedorder" //统一下单地址
const res = await uniCloud.httpclient.request(unifiedorder_url,{
method: 'POST',
data:val.xml
})
conslog.log(res);
6: 结果打印如下:我看不懂了
"data": {
"type": "Buffer",
"data": [62, 20, 109, 108, 62, 60, 114, 101, 116, 117, 114, 110, 95, 99, 111, 100, 101, 62, 60, 33, 91, 67, 68, 65, 84, 65, 91, 70, 65, 73, 76, 93, 93, 61, 60, 47, 114, 101, 116, 117, 114, 110, 95, 99, 111, 100, 101, 62, 10, 60, 114, 101, 116, 95, 159, 115, 103, 62, 60, 33, 91, 67, 68, 65, 84, 65, 91, 231, 173, 190, 219, 144, 141, 233, 148, 153, 232, 175, 175, 239, 188, 141, 22, 15, 13, 20, 16, 128, 230, 159, 65, 229, 144, 142, 229, 134, 141, 232, 175, 149, 93, 93, 62, 60, 47, 114, 10, 116, 117, 114, 110, 95, 10, 115, 103, 62, 10, 60, 43, 120, 109, 108, 62]
},
"status": 200,
"headers": {
"server": "nginx",
"date": "Mon, 08 May 2023 09:30:57 GMT",
"content-type": "text/plain",
"content-length": "126",
"connection": "keep-alive",
"keep-alive": "timeout=8",
"cache-control": "no-cache, must-revalidate",
"x-content-type-options": "nosniff",
"request-id": "08D182E3A206D2CD8C70283348, 08D182E3AA0D28C5820AB4B402-0"
},
"res": {
"status": 200,
"statusCode": 200,
"statusMessage": "OK",
"headers": {
"server": "nginx",
"date": "Mon, 08 May 2023 09:30:57 GMT",
"content-type": "text/plain",
"content-length": "126",
"connection": "keep-alive",
"keep-alive": "timeout=8",
"cache-control": "no-cache, must-revalidate",
"x-content-type-options": "nosniff",
"request-id": "08D182E3A2064A904-270283348, 08D182E3A206104B90828B4B402-0"
},
"size": 126,
"aborted": false,
"rt": 217,
"keepAliveSocket": false,
"data": {
"type": "Buffer",
"data": [62, 20, 109, 108, 62, 60, 114, 101, 116, 117, 114, 110, 95, 99, 111, 100, 101, 62, 60, 33, 91, 67, 68, 65, 84, 65, 91, 70, 65, 73, 76, 93, 93, 61, 60, 47, 114, 101, 116, 117, 114, 110, 95, 99, 111, 100, 101, 62, 10, 60, 114, 101, 116, 95, 159, 115, 103, 62, 60, 33, 91, 67, 68, 65, 84, 65, 91, 231, 173, 190, 219, 144, 141, 233, 148, 153, 232, 175, 175, 239, 188, 141, 22, 15, 13, 20, 16, 128, 230, 159, 65, 229, 144, 142, 229, 134, 141, 232, 175, 149, 93, 93, 62, 60, 47, 114, 10, 116, 117, 114, 110, 95, 10, 115, 103, 62, 10, 60, 43, 120, 109, 108, 62]
},
"requestUrls": ["https://api.mch.weixin.qq.com/pay/unifiedorder"],
"timing": null,
"remoteAddress": "221.238.80.33",
"remotePort": 443,
"socketHandledRequests": 1,
"socketHandledResponses": 1
}
pxd
- 发布:2023-05-09 14:53
- 更新:2023-05-10 11:41
- 阅读:250
1 个回复
DCloud_uniCloud_VK
你的问题在于uniCloud.httpclient.request 这个API默认就是返回二进制数据,想要返回json,要多传参数
dataType: 'json' // 指定返回值为json格式,自动进行parse
如果接受xml格式,则 dataType: 'text' // 指定返回值为text格式
友情提示:其实可以直接用uni-pay,这些你都不用对接了,直接调用方法就能用