php Laravel 微信支付V3 支付回调验证
·
话不多说直接上代码(如果有用的话-记得打赏哦)
/**
* 从证书中获取私钥
* @param $cert_path (微信平台证书---从《获取平台证书》接口中获得)
* @return bool
*/
function certPubKey($cert_path){
$cert_path = file_get_contents($cert_path);
$pub_key = openssl_pkey_get_public($cert_path);
if($pub_key){
$keyData = openssl_pkey_get_details($pub_key);
return $keyData['key'];
}
return false;
}
/**
* 验证回调主方法
* @param $http_data header头的信息(微信回调发送的header头)
* @param $body 应答主体信息 (微信发送的数据)(未解密的数据!!!)
* @return int 验证成功返回 1 失败返回 0
*/
function verifySigns($http_data,$body){
$wechatpay_timestamp = $http_data['Wechatpay-Timestamp'];
$wechatpay_nonce = $http_data['Wechatpay-Nonce'];
$wechatpay_signature = $http_data['Wechatpay-Signature'];
$signature = base64_decode($wechatpay_signature);
$pub_key = certPubKey('wxpay_key/cert.pem');//平台证书路径
$body = str_replace('\\','',$body);
$message =
$wechatpay_timestamp . "\n" .
$wechatpay_nonce . "\n" .
$body . "\n";
$res = openssl_verify($message,$signature, $pub_key,OPENSSL_ALGO_SHA256);
if ($res == 1) {
return 1;
}
return 0;
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)