Comments (3)
上代码:
$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 . '×tamp=' . 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;
}
请问返回如上内容是什么问题
from phpsm2sm3sm4.
看你关了应该是解决,招行这个问题,一般
- 是双方的结果格式的匹配上的问题
- 密钥格式的问题,你调用的这个函数接收的是 hex的 128或04开头130字节的hex字符串,
from phpsm2sm3sm4.
问题已解决,是开头04的问题,谢谢
from phpsm2sm3sm4.
Related Issues (20)
- HMAC-SM3 请问这个能否实现呢 HOT 3
- 求大佬帮看看sm2签名,java的可以通过,但是php的签名就没有办法通过,对接国家医保支付 HOT 1
- 大神你好,请问 hmac-sm3 具体怎么做呢? HOT 1
- SM4 golang 版和 php 版本加密后数据不一致,求指点 HOT 6
- 使用sm4-ecb提示Uncaught Exception: 秘钥长度为16位 HOT 2
- 求助SM2解密问题 HOT 7
- 对接招行付款码收款支付,需要对终端数据进行加密,并且在要对随机私钥进行数字信封加密,进行测试时信封加密和招行不一致,加密结果也不一致 HOT 9
- sm2 缺少文件 HOT 4
- 对接招行时,对招行的数据返回进行验签时,偶现错误 ASN.1 Parser Exception at offset XX: Integer not minimally encoded HOT 2
- does not comply with psr-4 autoloading standard HOT 8
- Uncaught FG\ASN1\Exception\ParserException: ASN.1 Parser Exception HOT 5
- 对接国家医保平台的sm2withsm3的时候发现,这个签名的结果和java的签名不一致 HOT 7
- 加密无法解密 HOT 1
- Java 加密使用的是SM3withSm2,php生成签名验签不通过 HOT 9
- java代码生成的签名用php代码验签不通过 HOT 3
- java代码生成的sm2解密与php不一致, HOT 3
- 密钥 base64 转 hex 问题 HOT 8
- 对接招行使用sm3withsm2加密,按照示例写的加签方法在招行验证失败。 HOT 12
- 对接招行需要使用SM3withSM2,sm2加密需要用sm2p256v1。 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpsm2sm3sm4.