又遇到过这个问题的人么,好想知道怎么搞
云开发模拟器生成二维码可以支付,真机调试就说缺少total_fee,奇葩?云开发模拟器生成二维码可以支付,真机调试就说缺少total_fee,奇葩?找不到原因,是因为没上线么,还是哪里需要配置,微信真是奇葩,无语了,文档也好少,根本不明白为啥产生这个问题,怎么解决? const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) exports.main = async (event, context) => { const res = await cloud.cloudPay.unifiedOrder({ "body" : event.msg, // 商品描述 "outTradeNo" : event.outTradeNo, // 商户订单号 "spbillCreateIp" : "127.0.0.1", // 终端 IP "subMchId" : "16xxxx", // 商户号 "totalFee" : event.totalFee, // 总金额 "envId": "xxxxx", // 云函数环境名称 "functionName": "payback" // 支付结果通知回调云函数名 }) return res }
10-23 <xml><return_code><![CDATA[FAIL]]></return_code> <return_msg><![CDATA[签名错误,请检查后再试]]></return_msg> </xml>
微信云开发支付签名错误,请情况?说一下没有子商户,只有商户号,就是用的以前的支付接口,这是云开发没有后端代码那个notify_url不写还不行, 不知道哪里有问题, 签名在微信工具里验证通过,调用下单接口就报签名错误,希望会的人答疑解惑一下,谢谢啦 //2 openid 就是支付用户的识别号 const mch_id = 'xxx '; // 商户号 const key = 'xxxxx'; // 商户密钥 const cloud = require('wx-server-sdk') const rp = require('request-promise') const crypto = require('crypto') cloud.init() function getSign(args) { let sa = [] for (let k in args) sa.push(k + '=' + args[k]) sa.push('key=' + key) console.log(sa.join('&')) return crypto.createHash('md5').update(sa.join('&'), 'utf8').digest('hex').toUpperCase() } function getXml(args) { let sa = [] for (let k in args) sa.push('<' + k + '>' + args[k] + '</' + k + '>') sa.push('<sign>' + getSign(args) + '</sign>') let axml = '<xml>' + sa.join('') + '</xml>' console.log("最后签名:",axml) return axml } function getNonceStr(){ var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; var nums=""; for(var i=0;i<32;i++){ var id = parseInt(Math.random()*61); nums+=chars[id]; } nums= nums.toLowerCase() return nums ; } exports.main = async (event, context) => { const wxContext = cloud.getWXContext() const appId = appid = wxContext.APPID console.log("appid是:", appid, appId) console.log("key是:", key) const openid = wxContext.OPENID // const attach = 'attach' const body = event.msg; const total_fee = event.totalFee; const notify_url = "http://127.0.0.1" const spbill_create_ip = "127.0.0.1" const fee_type = "CNY" // const nonceStr = nonce_str = Math.random().toString(36).substr(2, 15) const nonceStr = nonce_str = getNonceStr() const timeStamp = parseInt(Date.now() / 1000) + '' const out_trade_no = event.outTradeNo; const trade_type = "JSAPI" const sign_type = "MD5" const xmlArgs = { appid, // attach, body, fee_type, mch_id, nonce_str, notify_url, openid, out_trade_no, sign_type, spbill_create_ip, total_fee, trade_type, } let xml = (await rp({ url: "https://api.mch.weixin.qq.com/pay/unifiedorder", method: 'POST', body: getXml(xmlArgs) })).toString("utf-8") console.log("签名是:",xml) if (xml.indexOf('prepay_id') < 0) return xml let prepay_id = xml.split("<prepay_id><![CDATA[")[1].split("]]></prepay_id>")[0] let payArgs = { appId, nonceStr, package: ('prepay_id=' + prepay_id), signType: 'MD5', timeStamp } return { ...payArgs, paySign: getSign(payArgs) } }
10-23