完善签名

This commit is contained in:
2020-10-13 16:59:05 +08:00
parent 4d97481515
commit 1dd3503ee8
3 changed files with 39 additions and 16 deletions

View File

@@ -38,10 +38,10 @@ class UnionPayController extends Controller
unset($inputs['sign']);
$action = new UnionPay($inputs, $sign);
$action->addLog();
// $action->addLog();
$action->start();
$action->updateLog();
// $action->updateLog();
return $action->respond();

View File

@@ -53,8 +53,10 @@ class Init
*/
public function checkSign($out = true, $self = false)
{
$sign = hex2bin($this->sign);
$sign = $this->hexXbin($this->sign);
if (!$sign) {
throw new \Exception('签名错误');
}
$public_key = $this->getPublic($self);
$pub_key_id = openssl_get_publickey($public_key);
@@ -72,6 +74,26 @@ class Init
return $result;
}
/**
* Notes: 校验sign
* @Author: 玄尘
* @Date : 2020/10/13 15:21
* @param $data
* @param false $types
* @return int|string
*/
public function hexXbin($sign, $types = false)
{
// 过滤非16进制字符
$checkStr = strspn($sign, '0123456789abcdefABCDEF');
//字符串长度不是偶数时pack来处理
if (strlen($checkStr) % 2) {
return pack("H*", $sign);
} else {
return hex2bin($sign);
}
}
/**
* Notes: 签名
* @Author: 玄尘

View File

@@ -40,10 +40,10 @@ class UnionPay extends Init
{
//设置基础数据
$this->getOutBaseData();
try {
//校验数据
$this->checkInData();
try {
//查询是否是幂等 就是重复查询
$this->idempotent();
//入库请求参数
@@ -148,6 +148,7 @@ class UnionPay extends Init
{
//验签
$res = $this->checkSign(false, false);
if ($res !== true) {
$this->msg_rsp_code = 9996;
$this->msg_rsp_desc = '验签失败';
@@ -222,9 +223,6 @@ class UnionPay extends Init
break;
//冲正
case '002101':
$basics = array_merge($basics, [
'msg_ver' => 0.1,
]);
//撤销
case '002102':
$basics = array_merge($basics, [
@@ -257,11 +255,14 @@ class UnionPay extends Init
public function updateOutData()
{
$this->outdata['sign'] = $this->getSign();
//如果有入库模型
if ($this->model) {
$this->model->out_source = $this->outdata;
if ($this->outdata['msg_rsp_code'] != '0000') {
$this->model->status = 0;
}
$this->model->save();
}
}