/**
* @Author:小破孩
* @Email:3584685883@qq.com
* @Time:2025/2/17 15:25
* @param $array
* @return string
* @Description:数组以key=value&key=value 返回字符串
*/
public function arrayKeyValueToString($array) {
$result = '';
foreach ($array as $key => $value) {
$result.= $key. '='. $value. '&';
}
// 去除末尾多余的 & 符号
return rtrim($result, '&');
}
/**
* @Author:小破孩
* @Email:3584685883@qq.com
* @Time:2025/2/14 15:32
* @return string
* @Description:生产签名
*/
public function setSign()
{
$data = [
'mchNo' => $this->payConfig['tppay_mchid'], // 商户号
'appId' => $this->payConfig['tppay_appid'], // appid
'reqTime' => $this->currentTimestamp, // 13位时间戳
'version' => "1.0", // 固定值
'signType' => 'RSA', // 验签方式
'mchOrderNo' => $this->orderNo, // 订单号
'amount' => (string)$this->amount, // 金额 单位 分
'body' => $this->body, // 商品描述
'notifyUrl' => $this->getNotifyUrl(), // 回调通知地址
'expiredTime' => '1800', // 订单超时支付时间 单位 秒
'channelExtra' => $this->channelExtra,
'payTypeInfo' => (string)$this->payTypeInfo(), // 收银台展示的付款方式
// 'directPayType'=> (string)$this->getPayType(), // 直接支付的支付方式
];
ksort($data);
// Log::write("发起签名的参数:".var_export($data,true),"tppay");
$instanceArr = new \app\common\lib\data\Arr();
$encodedParams = $instanceArr->arrayKeyValueToString($data);
Log::write("处理后的签名字符串:".PHP_EOL.var_export($encodedParams,true),"tppay");
$privateKey = "-----BEGIN PRIVATE KEY-----\n"
. $this->payConfig['tppay_rsa_private_key']
. "\n-----END PRIVATE KEY-----";
$publicKey = "-----BEGIN PUBLIC KEY-----\n"
. $this->payConfig['tppay_rsa_public_key']
. "\n-----END PUBLIC KEY-----";
// Log::write("发起签名的私钥:".var_export($privateKey,true),"tppay");
$instanceRsa = new \app\common\lib\pay\tppay\Rsa(null, null, $privateKey, $publicKey);
$encryptedWithPrivate = $instanceRsa->sign($encodedParams); //签名使用SHA1withRSA
// Log::write("签名的结果:".var_export($encryptedWithPrivate,true),"tppay");
return $encryptedWithPrivate;
}
版权属于:
小破孩
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论