这种情况大多是需要你检查你的sessionKey的有效性
虚拟支付 mp_sig签名一直抱错?[代码][代码] [代码] [代码][代码][代码] [代码][代码]function[代码] [代码]request_post([代码][代码]$url[代码] [代码], [代码][代码]$post_data[代码] [代码])[代码][代码][代码][代码] [代码][代码]{[代码][代码][代码][代码] [代码][代码]$data_string[代码] [代码]= json_encode([代码][代码]$post_data[代码][代码]);[代码][代码][代码][代码] [代码][代码]$ch[代码] [代码]= curl_init ();[代码][代码][代码][代码] [代码][代码]curl_setopt ( [代码][代码]$ch[代码][代码], CURLOPT_URL, [代码][代码]$url[代码] [代码]);[代码][代码][代码][代码] [代码][代码]curl_setopt ( [代码][代码]$ch[代码][代码], CURLOPT_POST, 1 );[代码][代码][代码][代码] [代码][代码]curl_setopt([代码][代码]$ch[代码][代码], CURLOPT_HEADER, false);[代码][代码][代码][代码] [代码][代码]curl_setopt([代码][代码]$ch[代码][代码], CURLOPT_SSL_VERIFYPEER, false);[代码][代码][代码][代码] [代码][代码]// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");[代码][代码][代码][代码] [代码][代码]curl_setopt([代码][代码]$ch[代码][代码], CURLOPT_POSTFIELDS,[代码][代码]$data_string[代码][代码]);[代码][代码][代码][代码] [代码][代码]curl_setopt([代码][代码]$ch[代码][代码], CURLOPT_RETURNTRANSFER,true);[代码][代码][代码][代码] [代码][代码]curl_setopt([代码][代码]$ch[代码][代码], CURLOPT_HTTPHEADER, [代码][代码]array[代码][代码]([代码][代码][代码][代码] [代码][代码]'Content-Type: application/json'[代码][代码],[代码][代码][代码][代码] [代码][代码]'Content-Length: '[代码] [代码]. [代码][代码]strlen[代码][代码]([代码][代码]$data_string[代码][代码])[代码][代码][代码][代码] [代码][代码]));[代码][代码][代码][代码] [代码][代码]$result[代码] [代码]= curl_exec([代码][代码]$ch[代码][代码]);[代码][代码][代码][代码] [代码][代码]if[代码] [代码](curl_errno([代码][代码]$ch[代码][代码])) {[代码][代码][代码][代码] [代码][代码]print[代码] [代码]curl_error([代码][代码]$ch[代码][代码]);[代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码] [代码][代码]curl_close([代码][代码]$ch[代码][代码]);[代码][代码][代码][代码] [代码][代码]return[代码] [代码]$result[代码] [代码];[代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码] [代码][代码]//创建签名 [代码][代码][代码][代码] [代码][代码]function[代码] [代码]create_sig( [代码][代码]$post_data[代码] [代码],[代码][代码]$appKey[代码][代码])[代码][代码][代码][代码] [代码][代码]{[代码][代码][代码][代码] [代码][代码]ksort([代码][代码]$post_data[代码][代码]);[代码][代码][代码][代码] [代码][代码]$o[代码] [代码]= [代码][代码]""[代码][代码];[代码][代码][代码][代码] [代码][代码]foreach[代码] [代码]( [代码][代码]$post_data[代码] [代码]as[代码] [代码]$k[代码] [代码]=> [代码][代码]$v[代码] [代码]) [代码][代码][代码][代码] [代码][代码]{ [代码][代码][代码][代码] [代码][代码]$o[代码][代码].= [代码][代码]"$k="[代码] [代码]. rawurlencode( [代码][代码]$v[代码] [代码]). [代码][代码]"&"[代码] [代码];[代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码] [代码][代码]$stringA[代码] [代码]= [代码][代码]substr[代码][代码]([代码][代码]$o[代码][代码],0,-1);[代码][代码][代码][代码] [代码][代码]// stringA+"&org_loc=/cgi-bin/midas/getbalance&method=POST&secret=zNLgAGgqsEWJOg1nFVaO5r7fAlIQxr1u"[代码][代码][代码][代码] [代码][代码]$stringSignTemp[代码][代码]=[代码][代码]$stringA[代码][代码].[代码][代码]"&org_loc=/cgi-bin/midas/getbalance&method=POST&secret="[代码][代码].[代码][代码]$appKey[代码][代码];[代码][代码][代码][代码] [代码][代码]// file_put_contents ( 'create_sig.log', $stringSignTemp . PHP_EOL, FILE_APPEND | LOCK_EX );[代码][代码][代码][代码] [代码][代码]$s[代码] [代码]= hash_hmac([代码][代码]'sha256'[代码][代码], [代码][代码]$stringSignTemp[代码][代码], [代码][代码]$appKey[代码][代码], false);[代码][代码][代码][代码] [代码][代码]// $s = hash_hmac('sha256', $stringSignTemp, strtr($appKey, '-_', '+/'), true);[代码][代码][代码][代码] [代码][代码]// $sig = base64_encode($s);[代码][代码][代码][代码] [代码][代码]$sig[代码] [代码]= [代码][代码]$s[代码] [代码];[代码][代码][代码][代码] [代码][代码]return[代码] [代码]$sig[代码][代码];[代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码] [代码][代码]function[代码] [代码]create_mp_sig( [代码][代码]$post_data[代码][代码],[代码][代码]$session_key[代码][代码])[代码][代码][代码][代码] [代码][代码]{[代码][代码][代码][代码] [代码] [代码][代码][代码] [代码][代码]ksort([代码][代码]$post_data[代码][代码]);[代码][代码][代码][代码] [代码][代码]$o[代码] [代码]= [代码][代码]""[代码][代码];[代码][代码][代码][代码] [代码][代码]foreach[代码] [代码]( [代码][代码]$post_data[代码] [代码]as[代码] [代码]$k[代码] [代码]=> [代码][代码]$v[代码] [代码]) [代码][代码][代码][代码] [代码][代码]{ [代码][代码][代码][代码] [代码][代码]$o[代码][代码].= [代码][代码]"$k="[代码] [代码]. rawurlencode( [代码][代码]$v[代码] [代码]). [代码][代码]"&"[代码] [代码];[代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码] [代码][代码]$stringA[代码] [代码]= [代码][代码]substr[代码][代码]([代码][代码]$o[代码][代码],0,-1);[代码][代码][代码][代码] [代码][代码]//$stringSignTemp=stringA+"&org_loc=/cgi-bin/midas/getbalance&method=POST&session_key=V7Q38/i2KXaqrQyl2Yx9Hg=="[代码][代码][代码][代码] [代码][代码]$stringSignTemp[代码][代码]=[代码][代码]$stringA[代码][代码].[代码][代码]"&org_loc=/cgi-bin/midas/getbalance&method=POST&session_key="[代码][代码].[代码][代码]$session_key[代码][代码];[代码][代码][代码][代码] [代码][代码]file_put_contents[代码] [代码]( [代码][代码]'create_mp_sig.log'[代码][代码], [代码][代码]$stringSignTemp[代码] [代码]. PHP_EOL, FILE_APPEND | LOCK_EX );[代码][代码][代码][代码] [代码][代码]$s[代码] [代码]= hash_hmac([代码][代码]'sha256'[代码][代码], [代码][代码]$stringSignTemp[代码][代码], [代码][代码]$session_key[代码][代码], false);[代码][代码][代码][代码] [代码][代码]// $s = hash_hmac('sha256', $stringSignTemp, strtr($session_key, '-_', '+/'), true);[代码][代码][代码][代码] [代码][代码]// $sig = base64_encode($s);[代码][代码][代码][代码] [代码][代码]$sig[代码] [代码]= [代码][代码]$s[代码] [代码];[代码][代码][代码][代码] [代码][代码]return[代码] [代码]$sig[代码][代码];[代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码] [代码][代码]$datastr[代码] [代码]= [代码][代码]file_get_contents[代码][代码]([代码][代码]'php://input'[代码][代码]);[代码][代码][代码][代码] [代码][代码]$data[代码] [代码]= json_decode([代码][代码]$datastr[代码][代码],true);[代码][代码][代码][代码] [代码][代码]// file_put_contents ( 'debug2222.log', var_export($data,true) . PHP_EOL, FILE_APPEND | LOCK_EX );[代码][代码][代码][代码] [代码] [代码][代码][代码] [代码][代码]$appSecret[代码] [代码]= [代码][代码]"修改xxx"[代码][代码];[代码][代码][代码][代码] [代码][代码]$appid[代码] [代码]= [代码][代码]"修改"[代码][代码];[代码][代码][代码][代码] [代码][代码]$offer_id[代码] [代码]= [代码][代码]"修改"[代码][代码]; [代码][代码]//米大师分配的offer_id[代码][代码][代码][代码] [代码] [代码][代码][代码] [代码][代码]$openid[代码] [代码]= [代码][代码]$data[代码][代码][[代码][代码]"openid"[代码][代码]]; [代码][代码]//[代码][代码][代码][代码] [代码][代码]$access_token[代码] [代码]= [代码][代码]$data[代码][代码][[代码][代码]"access_token"[代码][代码]];[代码][代码][代码][代码] [代码][代码]$session_key[代码] [代码]= [代码][代码]$data[代码][代码][[代码][代码]"session_key"[代码][代码]];[代码][代码][代码][代码] [代码][代码]$ts[代码] [代码]= time();[代码][代码][代码][代码] [代码][代码]$zone_id[代码] [代码]= [代码][代码]"1"[代码][代码];[代码][代码][代码][代码] [代码][代码]$pf[代码] [代码]= [代码][代码]"android"[代码][代码];[代码][代码][代码][代码] [代码][代码]$test[代码] [代码]= true;[代码][代码][代码][代码] [代码][代码]//正式[代码][代码][代码][代码] [代码][代码]$api[代码] [代码]= [代码][代码]"https://api.weixin.qq.com/cgi-bin/midas/getbalance?access_token=$access_token"[代码][代码];[代码][代码][代码][代码] [代码][代码]$offerSecret[代码] [代码]= [代码][代码]"修改"[代码][代码];[代码][代码][代码][代码] [代码][代码]//测试[代码][代码][代码][代码] [代码][代码]if[代码][代码]([代码][代码]$test[代码][代码])[代码][代码][代码][代码] [代码][代码]{[代码][代码][代码][代码] [代码][代码]$api[代码] [代码]= [代码][代码]"https://api.weixin.qq.com/cgi-bin/midas/sandbox/getbalance?access_token=$access_token"[代码][代码];[代码][代码][代码][代码] [代码][代码]$offerSecret[代码] [代码]= [代码][代码]"修改"[代码][代码];[代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码] [代码][代码]if[代码][代码](isset([代码][代码]$openid[代码][代码]))[代码][代码][代码][代码] [代码][代码]{[代码][代码][代码][代码] [代码][代码]$dataArr[代码] [代码]= [代码][代码]array[代码][代码]([代码][代码]"openid"[代码][代码]=>[代码][代码]$openid[代码][代码],[代码][代码]"appid"[代码][代码]=>[代码][代码]$appid[代码][代码],[代码][代码]"offer_id"[代码][代码]=>[代码][代码]$offer_id[代码][代码],[代码][代码]"ts"[代码][代码]=>[代码][代码]$ts[代码][代码],[代码][代码]"zone_id"[代码][代码]=>[代码][代码]$zone_id[代码][代码],[代码][代码]"pf"[代码][代码]=>[代码][代码]$pf[代码][代码]);[代码][代码][代码][代码] [代码][代码]$testSign1[代码] [代码]= create_sig([代码][代码]$dataArr[代码][代码],[代码][代码]$offerSecret[代码][代码]);[代码][代码][代码][代码] [代码][代码]$dataArr2[代码] [代码]= [代码][代码]array[代码][代码]([代码][代码]"openid"[代码][代码]=>[代码][代码]$openid[代码][代码],[代码][代码]"appid"[代码][代码]=>[代码][代码]$appid[代码][代码],[代码][代码]"offer_id"[代码][代码]=>[代码][代码]$offer_id[代码][代码],[代码][代码]"ts"[代码][代码]=>[代码][代码]$ts[代码][代码],[代码][代码]"zone_id"[代码][代码]=>[代码][代码]$zone_id[代码][代码],[代码][代码]"pf"[代码][代码]=>[代码][代码]$pf[代码][代码],[代码][代码]"access_token"[代码][代码]=>[代码][代码]$access_token[代码][代码],[代码][代码]"sig"[代码][代码]=>[代码][代码]$testSign1[代码][代码]);[代码][代码][代码][代码] [代码][代码]$mp_sig[代码] [代码]= create_mp_sig([代码][代码]$dataArr2[代码][代码],[代码][代码]$session_key[代码][代码]);[代码][代码][代码][代码] [代码][代码]$dataArr3[代码] [代码]= [代码][代码]array[代码][代码]([代码][代码]"openid"[代码][代码]=>[代码][代码]$openid[代码][代码],[代码][代码]"appid"[代码][代码]=>[代码][代码]$appid[代码][代码],[代码][代码]"offer_id"[代码][代码]=>[代码][代码]$offer_id[代码][代码],[代码][代码]"ts"[代码][代码]=>[代码][代码]$ts[代码][代码],[代码][代码]"zone_id"[代码][代码]=>[代码][代码]$zone_id[代码][代码],[代码][代码]"pf"[代码][代码]=>[代码][代码]$pf[代码][代码],[代码][代码]"access_token"[代码][代码]=>[代码][代码]$access_token[代码][代码],[代码][代码]"sig"[代码][代码]=>[代码][代码]$testSign1[代码][代码],[代码][代码]"mp_sig"[代码][代码]=>[代码][代码]$mp_sig[代码][代码]);[代码][代码][代码][代码] [代码][代码]$result[代码] [代码]= request_post([代码][代码]$api[代码][代码],[代码][代码]$dataArr3[代码][代码]);[代码][代码][代码][代码] [代码][代码]file_put_contents[代码] [代码]( [代码][代码]'debug333.log'[代码][代码], var_export([代码][代码]$dataArr3[代码][代码],true) . PHP_EOL, FILE_APPEND | LOCK_EX );[代码][代码][代码][代码] [代码][代码]file_put_contents[代码] [代码]( [代码][代码]'debug2222.log'[代码][代码], [代码][代码]$result[代码] [代码]. PHP_EOL, FILE_APPEND | LOCK_EX );[代码][代码][代码][代码] [代码][代码]print_r([代码][代码]$result[代码][代码]);[代码][代码][代码][代码] [代码][代码]// $dataArrTest = array("openid"=>"odkx20ENSNa2w5y3g_qOkOvBNM1g","appid"=>"wx1234567","offer_id"=>"12345678","ts"=>"1507530737","zone_id"=>pf,"sig"=>"1ad64e8dcb2ec1dc486b7fdf01f4a15159fc623dc3422470e51cf6870734726b","access_token"=>"ACCESSTOKEN");[代码][代码][代码][代码] [代码][代码]// $sigTest = create_mp_sig($dataArrTest,"V7Q38/i2KXaqrQyl2Yx9Hg==");[代码][代码][代码][代码] [代码][代码]// file_put_contents ( 'test.log', $sigTest . PHP_EOL, FILE_APPEND | LOCK_EX );[代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码]?>[代码][代码] 在接内购 ,一直卡在 mp_sig 抱错 :{"errcode":90009,"errmsg":"mp_sig error hint: [r16KCA0903e257]"} 可是这个算法 用上微信官方的例子给出的参数 是和文档一模一样的 。为什么实际测试就会出现mp_sig 这个算法我已经参照文档反复比对。还是抱这个错,哪位大佬能指正下到底是哪里出问题了。文档参照的: https://developers.weixin.qq.com/minigame/dev/tutorial/open-ability/midas-signature.html
2018-09-27这种情况一般考虑是appkey有误 可能用的是沙箱的appkey
midasGetBalance 90011 sig errorPHP后端请求 按照文档的签名算法 [图片] PHP实现 $stringA = "appid=".config('wx')['appid']."&offer_id=1450016276&openid=".$openid."&pf=android&ts=".$time."&zone_id=1"; $stringSignTemp= $stringA."&org_loc=/cgi-bin/midas/sandbox/getbalance&method=POST&secret=zNLgAGgqsEWJOg1nFVaO5r7fAlIQxr1u"; $sig = hash_hmac('sha256', $stringSignTemp, 'zNLgAGgqsEWJOg1nFVaO5r7fAlIQxr1u'); 返回错误 {"errcode":90011,"errmsg":"sig error hint: [JdHZea0977shb1]"} 一开始是mp_sig错误 ,解决了mp_sig问题后出现sig错误,算法检查了很多次,还是一直失败
2018-09-27