mock原理
通过hosts指向自己部署的服务,模拟返回第三方支付端参数达到支付mock效果
工具准备
python,flask,stunnel(生成本地pem后缀证书用于访问https,依赖openssl,证书放在flask同目录下)
paymock脚本编码(基于flask)
|
|
生成vpsee证书(通过stunnel)
- openssl genrsa -out key.pem 2048
- openssl req -new -x509 -key key.pem -out cert.pem -days 1095
- cat key.pem cert.pem >>vpsee.pem
https代理配置
123456789pid =cert = vpsee.pemdebug = 7foreground = yes[https]accept = 443connect = 80`
部署mock前端
包含static和templates文件夹
修改alipay配置(以修改php文件为例,pc端)
修改alipay源码;
/xxxx.com/ThinkPHP/Extend/Vendor/Alipay/alipay_notify.class.php12345678function verifyNotify()注释(//$isSign = $this->getSignVeryfy($_POST, $_POST["sign"]);)添加 $isSign = true;注释( //if (! empty($_POST["notify_id"])) {$responseTxt = $this->getResponse($_POST["notify_id"]);})function verifyReturn()注释(//$isSign = $this->getSignVeryfy($_REQUEST, $_REQUEST["sign"]);)添加 $isSign = true;新增支付服务ua
12/xxxx/Conf/config.php add 'GATEWAY_USER_AGENT'=> 'wushi',rm -rf /xxxx/Runtime/*修改支付回调url
1234567891011121314/xxxx.com/Conf/config.php//支付异步回调通知URL(todo 正式环境地方)'PAY_ASYNCHRONOUS_CALLBACK' => 'http:/xxxx.com/paygate/gateway_pay_async_push',//支付同步回调通知URL(todo 正式环境地方)'PAY_SYNCHRONOUS_CALLBACK' => 'http://xxxx.com/paygate/gateway_pay_sync_push',//退款异步回调通知URL(todo 正式环境地方)'REFUND_ASYNCHRONOUS_CALLBACK' => 'http://xxxx.com/refundgate/gateway_refund_async_push',to//支付异步回调通知URL(todo 正式环境地方)'PAY_ASYNCHRONOUS_CALLBACK' => 'http://192.168.143.171:8139/paygate/gateway_pay_async_push',//支付同步回调通知URL(todo 正式环境地方)'PAY_SYNCHRONOUS_CALLBACK' => 'http://192.168.143.171:8139/paygate/gateway_pay_sync_push',//退款异步回调通知URL(todo 正式环境地方)'REFUND_ASYNCHRONOUS_CALLBACK' => 'http://192.168.143.171:8139/refundgate/gateway_refund_async_push',
rm -rf /xxxx.com/Runtime/*
- 配置host
192.168.149.34 mapi.alipay.com