作者 Cool
1 个管道 的构建 失败 耗费 0 秒

支付及回调调试

... ... @@ -724,22 +724,7 @@ class Goods extends Api
'payment' => [
'merchant_id' => $config['MCHIDGZH'],
'key' => $config['APIKEYGZH'],
'notify_url' => \think\Request::instance()->domain().addon_url('litestore/api.order/callback_for_wxgzh'),
],
];
$this->wxapp = new WXPAY_APP($options);
}
private function init_wx_pay_for_wxapp(){
$config = get_addon_config('litestore');
$options = [
'app_id' => $config['AppID'],
'secret' => $config['AppSecret'],
'payment' => [
'merchant_id' => $config['MCHID'],
'key' => $config['APIKEY'],
'notify_url' => \think\Request::instance()->domain().addon_url('litestore/api.order/callback_for_wxapp'),
'notify_url' => \think\Request::instance()->domain().'/index/ajax/callback_for_wxgzh',
],
];
... ...
... ... @@ -2,8 +2,12 @@
namespace app\index\controller;
use addons\litestore\model\Litestoreorder;
use addons\third\model\Third;
use addons\wechat\library\Config as ConfigService;
use app\common\controller\Frontend;
use EasyWeChat\Foundation\Application;
use EasyWeChat\Foundation\Application as WXPAY_APP;
use think\Db;
use think\Lang;
... ... @@ -14,9 +18,16 @@ use think\Lang;
class Ajax extends Frontend
{
protected $noNeedLogin = ['lang','refund_notify'];
protected $noNeedLogin = ['lang','callback_for_wxgzh','refund_notify'];
protected $noNeedRight = ['*'];
protected $layout = '';
public function _initialize()
{
parent::_initialize();
$this->user_id = $this->auth->id;
$this->model = new Litestoreorder;
}
/**
* 加载语言包
... ... @@ -38,10 +49,66 @@ class Ajax extends Frontend
}
/**
* 支付结果回调
*/
public function callback_for_wxgzh(){
$this->init_wx_pay_for_gzh(false);
$response = $this->wxapp->payment->handleNotify(function($notify, $successful){
$order = $this->model->payDetail($notify->out_trade_no);
if (empty($order)) { // 如果订单不存在
return true;
//return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
}
if ($successful) {
$order->updatePayStatus($notify->transaction_id);
}
return true; // 返回处理完成
});
$response->send();
}
private function init_wx_pay_for_gzh($Ischeck=false){
//这里首先判断 此用户是否绑定了微信公众号
if($Ischeck){
$third = Third::where(['user_id' => $this->user_id, 'platform' => 'wechat'])->find();
if(!$third){
//从这里自动绑定微信公众号的账户
$this->error('您未绑定微信号',null,1008);
}
}
$config = get_addon_config('litestore');
$third_config = get_addon_config('third');
$third_options = array_intersect_key($third_config, array_flip(['wechat']));
$third_options = $third_options['wechat'];
$options = [
'debug' => true,
'log' => [
'level' => 'debug',
'file' => '/tmp/easywechat.log',
],
'app_id' => $third_options['app_id'],
'secret' => $third_options['app_secret'],
'payment' => [
'merchant_id' => $config['MCHIDGZH'],
'key' => $config['APIKEYGZH'],
'notify_url' => \think\Request::instance()->domain().addon_url('litestore/api.order/callback_for_wxgzh'),
],
];
$this->wxapp = new WXPAY_APP($options);
}
/**
* 退款结果回调
*/
public function refund_notify() {
$app = new Application();
$app = new Application(ConfigService::load());
$response = $app->payment->handleRefundNotify(function ($message, $reqInfo) {
// Log::write(date('Y-m-d H:i') . '订单退款操作,返回数据:' . json_encode($message, JSON_UNESCAPED_UNICODE), 'order_refund');
// 其中 $message['req_info'] 获取到的是加密解密信息
... ...
... ... @@ -11116,7 +11116,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2020-08-27 14:14:40 </div>
Generated on 2020-08-27 16:11:15 </div>
<div class="col-md-6" align="right">
<a href="./" target="_blank">社区</a>
</div>
... ...