作者 郭文星

123

@@ -230,5 +230,57 @@ class Api extends Controller @@ -230,5 +230,57 @@ class Api extends Controller
230 //你可以在这里定义你的提示信息,但切记不可在此编写逻辑 230 //你可以在这里定义你的提示信息,但切记不可在此编写逻辑
231 $this->success("恭喜你!支付成功!", addon_url("epay/index/index")); 231 $this->success("恭喜你!支付成功!", addon_url("epay/index/index"));
232 } 232 }
  233 + /**
  234 + * 年检支付成功回调
  235 + */
  236 + public function OrderPayNtf()
  237 + {
  238 + $type = $this->request->param('paytype', 'wechat');
  239 + //file_put_contents("pcl_pay_p.log", date("Y-m-d H:i:s") . "::" . json_encode($this->request->param(), JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
  240 + $pay = \addons\epay\library\Service::checkNotify($type);
  241 + if (!$pay) {
  242 + echo '签名错误';
  243 + return;
  244 + }
  245 + $data = $pay->verify();
  246 + file_put_contents("pcl_pay_log.log", date("Y-m-d H:i:s") . "::" . json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
233 247
  248 + $payamount = $type == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
  249 + $out_trade_no = $data['out_trade_no'];
  250 +
  251 + //你可以在此编写订单逻辑
  252 + //判断是否已更新过支付状态
  253 + $cks = Db::name('order')
  254 + ->where(['order_no' => $data['out_trade_no']])
  255 + ->find();
  256 + if (!empty($cks) && $cks['is_pay'] == '2') {
  257 + //更新订单信息
  258 + $order['transaction_id'] = $data['transaction_id'];
  259 + $order['is_pay'] = 1;
  260 + $order['pay_time'] = time();
  261 + if ($cks['chejian_site_workers_id'] > 0) {
  262 + //$order['status'] = 3;
  263 + } else {
  264 + $order['status'] = 1;
  265 + }
  266 + $order['updatetime'] = time();
  267 + $rs = Db::name('order')
  268 + ->where(['order_no' => $data['out_trade_no']])
  269 + ->update($order);
  270 + //生成订单日志
  271 + if ($rs != false) {
  272 + $orderlog['order_id'] = $cks['id'];
  273 + $orderlog['content'] = '订单已支付';
  274 + $orderlog['user_id'] = $cks['user_id'];
  275 + $orderlog['step'] = 2;
  276 + $orderlog['createtime'] = time();
  277 + Db::name('order_log')->insertGetId($orderlog);
  278 +
  279 + }
  280 + }
  281 +
  282 + //你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
  283 + //下面这句必须要执行,且在此之前不能有任何输出
  284 + return $pay->success()->send();
  285 + }
234 } 286 }
@@ -2,13 +2,14 @@ @@ -2,13 +2,14 @@
2 2
3 namespace app\api\controller; 3 namespace app\api\controller;
4 4
  5 +use app\api\controller\v1\Base;
5 use app\common\controller\Api; 6 use app\common\controller\Api;
6 use think\Db; 7 use think\Db;
7 8
8 /** 9 /**
9 * 首页接口 10 * 首页接口
10 */ 11 */
11 -class Car extends Api 12 +class Car extends Base
12 { 13 {
13 protected $noNeedLogin = ['*']; 14 protected $noNeedLogin = ['*'];
14 protected $noNeedRight = ['*']; 15 protected $noNeedRight = ['*'];
@@ -101,7 +102,7 @@ class Car extends Api @@ -101,7 +102,7 @@ class Car extends Api
101 ->where(['id' => $this->auth->id]) 102 ->where(['id' => $this->auth->id])
102 ->field('id,wx_xcx_openid') 103 ->field('id,wx_xcx_openid')
103 ->find(); 104 ->find();
104 - $notifyURI = 'https://wyc.tenyes.cn/addons/epay/api/notifyx/type/wechat'; 105 + $notifyURI = $this->doman . '/addons/epay/api/OrderPayNtf';
105 $params = [ 106 $params = [
106 'amount' => $data['price'], 107 'amount' => $data['price'],
107 'orderid' => $data['order_no'], 108 'orderid' => $data['order_no'],
@@ -110,11 +111,8 @@ class Car extends Api @@ -110,11 +111,8 @@ class Car extends Api
110 'method' => 'miniapp', 111 'method' => 'miniapp',
111 'openid' => $userinfo['wx_xcx_openid'], 112 'openid' => $userinfo['wx_xcx_openid'],
112 ]; 113 ];
113 -  
114 $f = \addons\epay\library\Service::submitOrder($params); 114 $f = \addons\epay\library\Service::submitOrder($params);
115 - print_r($f);return;  
116 -  
117 - $this->success("请求成功",$res); 115 + $this->success("请求成功",$f);
118 116
119 117
120 } 118 }
@@ -19,6 +19,7 @@ class Base extends Api @@ -19,6 +19,7 @@ class Base extends Api
19 { 19 {
20 parent::__construct($request); 20 parent::__construct($request);
21 $this->qiniuUrl = 'https://qiniu.ask.xp.yn.cn'; 21 $this->qiniuUrl = 'https://qiniu.ask.xp.yn.cn';
  22 + $this->doman = 'https://wyc.tenyes.cn/';
22 $this->AppID = config("site.wxxcx_AppID");//微信小程序AppID 23 $this->AppID = config("site.wxxcx_AppID");//微信小程序AppID
23 $this->AppSecret = config("site.wxxcx_AppSecret");//微信小程序密钥 24 $this->AppSecret = config("site.wxxcx_AppSecret");//微信小程序密钥
24 } 25 }