- 微信企业付款接口,签名校验工具已正确,但还是返回【签名错误】
请求接口: https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers [图片] 各个参数已经按照文档:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 仔细检查过一篇。 请求参数,敏感信息已屏蔽: [代码]<?[代码][代码]xml[代码] [代码]version[代码][代码]=[代码][代码]"1.0"[代码] [代码]encoding[代码][代码]=[代码][代码]"UTF-8"[代码] [代码]standalone[代码][代码]=[代码][代码]"no"[代码][代码]?>[代码][代码]<[代码][代码]xml[代码][代码]>[代码][代码]<[代码][代码]amount[代码][代码]>30</[代码][代码]amount[代码][代码]>[代码][代码]<[代码][代码]nonce_str[代码][代码]>**</[代码][代码]nonce_str[代码][代码]>[代码][代码]<[代码][代码]mchid[代码][代码]>**</[代码][代码]mchid[代码][代码]>[代码][代码]<[代码][代码]partner_trade_no[代码][代码]>888820190116103208693299</[代码][代码]partner_trade_no[代码][代码]>[代码][代码]<[代码][代码]openid[代码][代码]>***-1-OF0c</[代码][代码]openid[代码][代码]>[代码][代码]<[代码][代码]mch_appid[代码][代码]>**</[代码][代码]mch_appid[代码][代码]>[代码][代码]<[代码][代码]sign[代码][代码]>E26C6EC2D205D60DA9920F74DD046822</[代码][代码]sign[代码][代码]>[代码][代码]<[代码][代码]check_name[代码][代码]>NO_CHECK</[代码][代码]check_name[代码][代码]>[代码][代码]<[代码][代码]spbill_create_ip[代码][代码]>***</[代码][代码]spbill_create_ip[代码][代码]>[代码][代码]<[代码][代码]sign_type[代码][代码]>MD5</[代码][代码]sign_type[代码][代码]>[代码][代码]<[代码][代码]desc[代码][代码]>C大调祝你新春快乐!</[代码][代码]desc[代码][代码]>[代码][代码]</[代码][代码]xml[代码][代码]>[代码] 返回结果: [代码]<?[代码][代码]xml[代码] [代码]version[代码][代码]=[代码][代码]"1.0"[代码] [代码]encoding[代码][代码]=[代码][代码]"utf-8"[代码][代码]?>[代码] [代码]<[代码][代码]xml[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]return_code[代码][代码]>[代码][代码]<![CDATA[SUCCESS]]>[代码][代码]</[代码][代码]return_code[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]return_msg[代码][代码]>[代码][代码]<![CDATA[SIGN_ERROR]]>[代码][代码]</[代码][代码]return_msg[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]mch_appid[代码][代码]>[代码][代码]<![CDATA[***]]>[代码][代码]</[代码][代码]mch_appid[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]mchid[代码][代码]>[代码][代码]<![CDATA[***]]>[代码][代码]</[代码][代码]mchid[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]result_code[代码][代码]>[代码][代码]<![CDATA[FAIL]]>[代码][代码]</[代码][代码]result_code[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]err_code[代码][代码]>[代码][代码]<![CDATA[SIGN_ERROR]]>[代码][代码]</[代码][代码]err_code[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]err_code_des[代码][代码]>[代码][代码]<![CDATA[签名错误]]>[代码][代码]</[代码][代码]err_code_des[代码][代码]>[代码][代码]</[代码][代码]xml[代码][代码]>[代码] 请问哪里还需要检查的?
2019-01-16 - 云开发生成小程序二维码,有需要的进。
真机测试已通过。 小程序端: wx.cloud.callFunction({ name: 'getQRCode', data: { scene: 'scene', page: 'pages/index/index', width: 180 } }).then(res => { let qr = "data:image/png;base64," + wx.arrayBufferToBase64(res.result) }) 云函数:getQRCode: const secret = 'your secret' const rp = require('request-promise') exports.main = async (event, context) => { let opt = { method: 'GET', url: 'https://api.weixin.qq.com/cgi-bin/token', qs: { appid: event.userInfo.appId, secret, grant_type: 'client_credential' }, json: true } let res = await rp(opt) opt = { method: 'POST', url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + res.access_token, body: { 'page': event.page, 'width': event.width, 'scene': event.scene }, json: true, encoding: null } return await rp(opt) }
2018-12-07 - 云开发支付的代码,有需要的进。
真机测试已通过。你照抄就行,保证可通过。 最新完美版本可供参考: https://developers.weixin.qq.com/community/develop/article/doc/0004c4a50a03107eaa79f03cc56c13 小程序端: wx.cloud.callFunction({ name: 'getPay' , data: { total_fee: parseFloat(0.01).toFixed(2) * 100, attach: 'anything', body: 'whatever' } }) .then( res => { wx.requestPayment({ appId: res.result.appid, timeStamp: res.result.timeStamp, nonceStr: res.result.nonce_str, package: 'prepay_id=' + res.result.prepay_id, signType: 'MD5', paySign: res.result.paySign, success: res => { console.log(res) } }) }) 云函数:getPay getPay目录下共两个文件: 1、index.js 2、package.json index.js代码如下: const key = "YOURKEY1234YOURKEY1234YOURKEY123"//这是商户的key,不是小程序的密钥,32位。 const mch_id = "1413090000" //你的商户号 //将以上的两个参数换成你的,然后以下可以不用改一个字照抄 const rp = require('request-promise') const crypto = require('crypto') function paysign({ ...args }) { let sa = [] for (let k in args) sa.push( k + '=' + args[k]) sa.push( 'key=' + key) return crypto.createHash('md5').update(sa.join('&'), 'utf8').digest('hex').toUpperCase() } exports.main = async (event, context) => { const appid = event.userInfo.appId const openid = event.userInfo.openId const attach = event.attach const body = event.body const total_fee = event.total_fee const notify_url = "https://whatever.com/notify" const spbill_create_ip = "118.89.40.200" const nonce_str = Math.random().toString(36).substr(2, 15) const timeStamp = parseInt(Date.now() / 1000) + '' const out_trade_no = "otn" + nonce_str + timeStamp let formData = "<xml>" formData += "<appid>" + appid + "</appid>" formData += "<attach>" + attach + "</attach>" formData += "<body>" + body + "</body>" formData += "<mch_id>" + mch_id + "</mch_id>" formData += "<nonce_str>" + nonce_str + "</nonce_str>" formData += "<notify_url>" + notify_url + "</notify_url>" formData += "<openid>" + openid + "</openid>" formData += "<out_trade_no>" + out_trade_no + "</out_trade_no>" formData += "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>" formData += "<total_fee>" + total_fee + "</total_fee>" formData += "<trade_type>JSAPI</trade_type>" formData += "<sign>" + paysign({ appid, attach, body, mch_id, nonce_str, notify_url, openid, out_trade_no, spbill_create_ip, total_fee, trade_type: 'JSAPI' }) + "</sign>" formData += "</xml>" let res = await rp({ url: "https://api.mch.weixin.qq.com/pay/unifiedorder", method: 'POST',body: formData}) let xml = res.toString("utf-8") if (xml.indexOf('prepay_id')<0) return xml let prepay_id = xml.split("<prepay_id>")[1].split("</prepay_id>")[0].split('[')[2].split(']')[0] let paySign = paysign({ appId: appid, nonceStr: nonce_str, package: ('prepay_id=' + prepay_id), signType: 'MD5', timeStamp: timeStamp }) return { appid, nonce_str, timeStamp, prepay_id, paySign } } package.json 代码如下: { "name": "getPay", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "youself", "license": "ISC", "dependencies": { "crypto": "^1.0.1", "request-promise": "^4.2.2" } } 最后选择:上传和部署:云端安装依赖。
2019-12-14