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_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);
$stringSignTemp = $stringA . "&org_loc=/cgi-bin/midas/getbalance&method=POST&secret=" . $appKey ;
$s = hash_hmac( 'sha256' , $stringSignTemp , $appKey , false);
$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=" . $session_key ;
file_put_contents ( 'create_mp_sig.log' , $stringSignTemp . PHP_EOL, FILE_APPEND | LOCK_EX );
$s = hash_hmac( 'sha256' , $stringSignTemp , $session_key , false);
$sig = $s ;
return $sig ;
}
$datastr = file_get_contents ( 'php://input' );
$data = json_decode( $datastr ,true);
$appSecret = "修改xxx" ;
$appid = "修改" ;
$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 );
}
?>
|
你好,麻烦问一下,这个问题怎么解决的呀,我也遇到了这样的问题,卡到心态爆炸了
这种情况大多是需要你检查你的sessionKey的有效性
我今天接支付也一直报这个错,你解决了吗
来个官方解答下啊,我测试按照文档的模拟数据都是和文档结果一致的,切成正式数据就签名错误,求解啊。也没有个固定的人,游戏就卡这了,等着上线呢