/**
* 支付宝 微信支付回调验签
* @param string $params 回调参数
* @param string $pkg 包名用来获取配置
* @return bool|mixed
*/
public static function verify($params = '',$pkg = 'com.wangduoduo.piece')
{
//获取配置
$config = SpiderBase::load_config($pkg);
//根据解码参数区别微信或支付宝
$data = self::xmlToArray($params);
if ($data) {
//微信回调
if ($data['return_code'] == "SUCCESS" && $data['result_code'] == "SUCCESS") {
$xmlsign = $data['sign'];
unset($data['sign'],$data['pay_type'],$data['pkg']);//这个是自定义回调时设置的参数,注意验签时要干掉 sign也要干掉
$sign = http_build_query($data);
$sign = strtoupper(md5($sign.'&key='.$config['wxPay']['key']));//签名
if ($sign == $xmlsign) {//验证
$data['pay_type'] = 1;
return $data;
}else{
return false;
}
}
}else{
//支付宝回调
parse_str($params,$data);//将支付宝回调参数转为array
unset($data['pay_type'],$data['pkg']);//这个是自定义回调时设置的参数,注意验签时要干掉 sign会在支付宝官方类库中过滤
$aop = new AopClient();
$aop->alipayrsaPublicKey = $config['alipay']['alipayrsaPublicKey'];//注意此处为商户公钥不是应用公钥,要区别开
$res = $aop->rsaCheckV1($data,'','RSA2');//官方验签方法
if ($res) {
$data['pay_type'] = 2;
return $data;
}else{
return false;
}
}
}