招行收款通支付对接来了个国密sm2,sm3,文档也写得不完整,给的demo还是java,哎苦了我们php的,现在直接给出php版本$post_data = [ 'version'=>'2.0', 'merchId'=>$merc
招行收款通支付对接来了个国密sm2,sm3,文档也写得不完整,给的demo还是java,哎苦了我们php的,现在直接给出php版本$post_data = [ 'version'=>'2.0', 'merchId'=>$merchId, //商户号 'payNo'=>$payNo, 'orderId' => $orderId, 'feeAmt'=>$money, 'custName'=>$name, 'custPhone'=>$tel, 'userId'=>$userId, 'returnUrl'=>$returnUrl];ksort($post_data);//body SM3$jsonstr=json_encode($post_data);echo 'BODY:'; var_dump($jsonstr);$sign=$sm3->digest($jsonstr,1);//Header SM2$post_data_apisign = array();$post_data_apisign["appid"]=$appid;$post_data_apisign["secret"]=$appsecret;$post_data_apisign["timestamp"]=$timestamp;$post_data_apisign["sign"]=$sign;//$apisign = Sign($post_data_apisign,$privateKey);//签名ksort($post_data_apisign);$post_data_apisign = ToUrlParams($post_data_apisign);$apisign = $sm2->doSign($post_data_apisign,$privateKey,'1234567812345678');$apisign = SM2_Asn1ToRaw($apisign);echo '
';$header = get_header_arr($sign,$apisign,$appid,$appsecret,$timestamp,$verify);var_dump($header);$result = curl_post($requert_url,$jsonstr,$header);var_dump($result);$result = json_decode($result,true);if($result['respCode'] == 'CMBMB99'){ header("location:{$result['sytUrl']}");}function ToUrlParams(array $array){ $buff = ""; foreach ($array as $k => $v) { if($v != "" && !is_array($v)){ $buff .= $k . "=" . $v . "&"; } } $buff = trim($buff, "&"); return $buff;}function SM2_Asn1ToRaw($apisign){ $apisign = hex2bin($apisign); $bytes = array_values(unpack('C*', $apisign)); $pos = 3; if ($bytes[$pos] == 32) { $pos += 1; } elseif ($bytes[$pos] == 33) { $pos += 2; } $data = array_slice($bytes, $pos, 32); $pos += 32; $pos += 1; if ($bytes[$pos] == 32) { $pos += 1; } elseif ($bytes[$pos] == 33) { $pos += 2; } $data = array_merge($data, array_slice($bytes, $pos, 32)); $str = pack('C*', ...$data); return bin2hex($str);}function curl_post($url,$params,$header){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); if(!empty($header)){ curl_setopt ( $curl, CURLOPT_HttpHEADER, $header ); } if(is_array($params)){ $params = JSON_encode($params); } curl_setopt($curl, CURLOPT_POSTFIELDS,$params); $data = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl);//关闭cURL会话 return $data;}
另外,很多人来问sm2和sm3的封装类再哪,百度、GitHub上面很多,下面给出一个一个地址,有需要自取,原封不动引入调用下就行:https://github.com/lpilp/phpsm2sm3sm4
来源地址:https://blog.csdn.net/liumengxiao2/article/details/125762051
--结束END--
本文标题: 招行收款通支付对接来了个国密sm2,sm3,文档也写得不完整,给的demo还是java,哎苦了我们php的,现在直接给出php版本
本文链接: https://lsjlt.com/news/402158.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0