微信扫码支付模式二回调问题 [ 1.1 版本 ]
$input->SetNotify_url("https://www.test.com/wxpay/notify");
这样设置后,扫码支付完成,微信并没有返回消息到wxpayController下的actionNotify方法里,通过打log发现跑到了index.php入口文件里了,我在根目录下建了一个wxpay文件夹,把微信支付官方demo里的notify.php拷进去,$input->SetNotify_url("https://www.test.com/wxpay/notify.php");
这样的话能进入到wxpay文件夹的notify.php文件中,但是这种是面向过程的写法,和框架里的写法完全不统一,不知道有遇到类似问题的没
366675462 补充于 2017-01-12 10:30
问题已经解决,是开启了csrf验证的原因,通过抓包发现外部访问/wxpay/notify抛400,去掉csrf解决了问题
366675462 补充于 2017-01-12 13:32
刚有人问到怎么关闭csrf验证,网上有很多方法,比如看到在初始化里$this->enableCsrfValidation = false
来关闭,由于我们项目对绝大部分组件进行了继承重写,所以我是直接在配置里修改的,我们在components组件下加了LHttpRequest继承CHttpRequest,
重写了normalizeRequest方法,里面有关闭csrf验证的,代码如下:
class LHttpRequest extends CHttpRequest
{
public $noCsrfValidationRoutes = array();
protected function normalizeRequest()
{
parent::normalizeRequest();
if ($this->enableCsrfValidation)
{
$url = Yii::app()->getUrlManager()->parseUrl($this);
foreach ($this->noCsrfValidationRoutes as $route)
{
if (strpos($url,$route) === 0)
{
Yii::app()->detachEventHandler('onBeginRequest', array($this,'validateCsrfToken'));
break;
}
}
}
}
}
然后配置文件main.php里,修改如下:
'components' => array(
'request' => array(
'class' => 'components.LHttpRequest',
'enableCookieValidation' => true,
'enableCsrfValidation' => true,
'noCsrfValidationRoutes' => array('pay/callback'),
),
),
配置后pay/callback就相当于关闭了csrf验证,方法有很多,我这个可能不是很好,只是结合自己的项目比较方便的一种,网上还有很多其他方法,以上仅供参考
366675462
注册时间:2014-08-18
最后登录:2018-10-23
在线时长:1小时59分
最后登录:2018-10-23
在线时长:1小时59分
- 粉丝2
- 金钱5
- 威望0
- 积分15