小游戏虚拟支付问题
沙盒测试要扣费
刚刚开始介入的时候,能用沙盒测试,正常扣费,现在发起扣费一直返回:-1 system error ,安照官方建议的方式多调用几次,还是一直返回 -1。
沙盒调用的是如下接口:
https://api.weixin.qq.com/cgi-bin/midas/sandbox/pay?access_token=%s
https://api.weixin.qq.com/cgi-bin/midas/sandbox/getbalance?access_token=%s
2 回复
module.exports = { appid: 'wxfece06b250c43b30' , appkey: '删除' , offer_id: '1450014752' , getAccessToken: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s' , // midas_appKey:'sLSwZFHLzNSsS0keKthlM6nVbK5Jcf2j', //正式 midas_appKey: 'mG3RyOCbrgytXzTU43fpbDtCdLDpmdto' , //沙箱 //扣除玩家游戏币 // MIDASPAY:'https://api.weixin.qq.com/cgi-bin/midas/pay?access_token=%s', MIDASPAY: 'https://api.weixin.qq.com/cgi-bin/midas/sandbox/pay?access_token=%s' , // MIDASPAY_ORG_LOC:'/cgi-bin/midas/pay', MIDASPAY_ORG_LOC: '/cgi-bin/midas/sandbox/pay' , // GETBALANCE:'https://api.weixin.qq.com/cgi-bin/midas/getbalance?access_token=%s', GETBALANCE: 'https://api.weixin.qq.com/cgi-bin/midas/sandbox/getbalance?access_token=%s' , // GETBALANCE_ORG_LOC:'/cgi-bin/midas/getbalance', GETBALANCE_ORG_LOC: '/cgi-bin/midas/sandbox/getbalance' , }; 逻辑代码片段: 1. 构建body function buildPayBody(data){ logger.error( '_buildPayBody data=' ,data); let sdkData = { openid: data.account.channel_account_id, appid: this ._config.appid, offer_id: this ._config.offer_id, ts: Number.parseInt(Date.now()/1000), zone_id: '1' , pf: this ._getPFTag(data.account.platform), amt: data.amt, bill_no: data.bill_no, }; sdkData = this ._sortObject(sdkData); logger.error( '_buildPayBody sdkData=' , sdkData); let sigOriStr = '' ; for (let key in sdkData){ sigOriStr += `${key}=${sdkData[key]}&`; } sigOriStr = sigOriStr.substring(0, sigOriStr.length - 1); let org_loc = `${ this ._config.MIDASPAY_ORG_LOC}&method=POST`; sdkData.sig = this ._getSha256(`${sigOriStr}&org_loc=${org_loc}&secret=${ this ._config.midas_appKey}`, this ._config.midas_appKey); sdkData.access_token = this ._access_token; sdkData = this ._sortObject(sdkData); let mp_sigOriStr = '' ; for (let key in sdkData){ mp_sigOriStr += `${key}=${sdkData[key]}&`; } mp_sigOriStr = mp_sigOriStr.substring(0, mp_sigOriStr.length - 1); sdkData.mp_sig = this ._getSha256(`${mp_sigOriStr}&org_loc=${org_loc}&session_key=${data.account.extend.session_key}`, data.account.extend.session_key); return sdkData; } 2.调用http支付 async function _payMoney(data, tryCount = 0){ try { let body = this ._buildPayBody(data); let resp = await httpclient.postData(body, util.format( this ._config.MIDASPAY, body.access_token)); if (!resp){ logger.error( '微信支付返回数据为空' ); throw ERROR_OBJ.DATA_NULL_ERROR; } resp = JSON.parse(resp); if (resp.errcode == 90013){ logger.error( '微信支付失败,余额不足, err=' , resp); throw ERROR_OBJ.AMOUNT_NOT_ENOUGH; } if (40001 == resp.errcode){ this ._access_token = null ; clearInterval( this ._access_token_timer); await this ._updateAccessToken(); return await this ._payMoney(data); } if (90013 == resp.errcode){ logger.error( '微信支付扣款余额不足, err=' , resp); throw {code:ERROR_OBJ.AMOUNT_NOT_ENOUGH.code, msg:JSON.stringify(resp)}; } if (-1 == resp.errcode && tryCount < 5){ tryCount++; return this ._payMoney(data, tryCount); } if (resp.errcode != 0){ logger.error( '微信支付扣款失败, err=' , resp); throw {code:ERROR_OBJ.CALL_SDK_FAIL.code, msg:JSON.stringify(resp)}; } return resp; } catch (err){ throw err; } } 3.问题描述 刚刚接入的时候,返回错误码是:-1,但错误描述是‘余额不足’,这种情况下,客户端支付后,服务端能正常调用pay接口,并返回金额等信息,这几天使用支付的时候,还是一直返:-1,sysem error。 |