亲身经历,官方文档坑
THPHP6,正常导入
composer require alipaysdk/easysdk
直接上内容,官方验签
//1. 设置参数(全局只需设置一次)Factory::setOptions(getOptions());
$result = Factory::payment()->common()->verifySign($_POST);
然而不好意思出现错误无法通过;主要原因fund_bill_list数据JSON字符串传递时序列化问题
// 请求数据处理
$data = request()->post();
$data = http_build_query($data);
$data = explode('&', $data);
$new_data = [];
foreach ($data as $key=>$val){
$rows = explode('=', $val);
$new_data[$rows[0]] = urldecode($rows[1]);
}
if (!empty($new_data['fund_bill_list'])){
$new_data['fund_bill_list'] = str_replace('"', '"', $new_data['fund_bill_list']);
$json = json_decode($new_data['fund_bill_list'], true);
if (json_last_error() !== JSON_ERROR_NONE) {
$this->consoleLog('Failed to decode JSON: ' . json_last_error_msg());
}
$new_data['fund_bill_list'] = json_encode($json);
}
// 才能去验证
$result = Factory::payment()->common()->verifySign($new_data);
如对你有帮助记得点赞哦~