lpilp / phpsm2sm3sm4

php版本,支持国密SM2的签名算法,非对称加解密,SM3的hash, SM4的对称加解密
320 stars 74 forks source link

调用CBS8 总提示致命错误 #68

Closed stevenliuhen closed 9 months ago

stevenliuhen commented 9 months ago

image

stevenliuhen commented 9 months ago

上代码: $cbs8_domain = 'https://cbs8-openapi-reprd.csuat.cmburl.cn'; $cbs8_token_url = $cbs8_domain.'/openapi/app/v1/app/token'; //应用ID $app_id = ''; //应用密钥 $app_secret = ''; //企业密钥 $customer_priKey = ''; //平台公钥 $cbs8_pubKey = '';

//获取token $data = []; $data['app_id'] = $app_id; $data['app_secret'] = $app_secret; $data['grant_type'] = 'client_credentials';

$header = [ 'Content-Type:application/json' ];

$response = get_request($cbs8_token_url, $header, 'POST', true, json_encode($data)); $response_content = json_decode($response, true); $token = $response_content['data']['token'];

echo "token: ", $token, " 有效期", $response_content['data']['expires'];

$userId = '1234567812345678'; $requestParam = [ 'accountNo' => '', ]; $requestJson = json_encode($requestParam);

$timestamp = (string)intval(microtime(true) * 1000); $document = $requestJson . '&timestamp=' . intval($timestamp);

$sm2 = new RtSm2('base64', false); $sign = $sm2->doSign($document, $customer_priKey, $userId);

//加密 $sm2 = new RtSm2(); $m2EncryptData = $sm2->doEncrypt($requestJson, $cbs8_pubKey);

$headers = []; $headers[] = 'Content-Type:application/json'; $headers[] = 'X-MBCLOUD-API-SIGN:'. trim($sign); $headers[] = 'Authorization:Bearer '.$token; $headers[] = 'X-MBCLOUD-TIMESTAMP:'. $timestamp;

$account_query_url = $cbs8_domain.'/openapi/account/openapi/v1/account/query';

//请求参数需要转换为二进制... var_dump(curlPost($account_query_url, hex2bin($m2EncryptData), $headers));

function curlPost($url, $data, $header = [], $timeout = 20) { $header = $header ? : ['Content-Type: application/json'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$rawResult = curl_exec($ch);//执行curl会话
echo ($rawResult);die;
// var_dump($rawResult);
// var_dump(curl_getinfo($ch));

$sm2 = new RtSm2();
var_dump($sm2->doDecrypt(bin2hex($rawResult), $customer_priKey, true));
print_r(json_decode($sm2->doDecrypt(bin2hex($rawResult), $customer_priKey, true), true));
die;
$result = json_decode($rawResult, true);
curl_close($ch);

return $result;

} 请问返回如上内容是什么问题

lpilp commented 9 months ago

看你关了应该是解决,招行这个问题,一般

stevenliuhen commented 9 months ago

问题已解决,是开头04的问题,谢谢