123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * AlipayController.php UTF-8
- * 支付宝对外处理页面
- *
- * @date : 2018/2/8 15:42
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace api\sdk\controller;
- use api\common\controller\V2ApiBaseController;
- use huo\controller\conf\PaywayConf;
- use huo\controller\pay\Notify;
- use huo\controller\pay\SdkOrderCache;
- use huo\controller\pay\SdkPayCache;
- use huolib\pay\Pay;
- use think\Config;
- class AlipayController extends V2ApiBaseController {
- function _initialize() {
- parent::_initialize();
- \think\Log::write($this->request->getContent(), 'error');
- Config::set('default_return_type', 'html');
- }
- /**
- * 支付宝支付回调地址
- * alipay/notify
- */
- public function notifyUrl() {
- $_class = new Notify();
- $_product_id = get_val($_REQUEST, 'body', '');
- $_order_id = get_val($_REQUEST, 'out_trade_no', '');
- $_class->notifyUrl('alipay', $_product_id, 0, $_order_id);
- }
- /**
- * 支付宝支付通知地址
- * alipay/return
- *
- * @return mixed
- * @throws \think\Exception
- */
- public function returnUrl() {
- $_order_id = $this->request->param('order_id/s', '');
- $_pay_class = Pay::ins()->get('alipay');
- $_pay_class->setOrderId($_order_id);
- /* 读取支付宝配置 start */
- $_order_data = SdkOrderCache::ins()->getInfoByOrderId($_order_id);
- $_app_id = $_order_data['app_id'] ?? 0;
- $_config = (new PaywayConf())->getConfByAppPayway($_app_id, 'alipay');
- $_pay_class->setConf($_config);
- /* 读取支付宝配置 end */
- $_pay_rs = $_pay_class->returnUrl();
- $this->assign('info', $_pay_rs);
- $_apple_id = $this->request->param('apple_id/s', '');
- $_msg = "支付成功!";
- $_return_token = '';
- if (!empty($_apple_id)) {
- //$_return_token = 'htsdk.com633403350://qo?oi='.$_pay_rs['order_id'].'&bt=1&st=2';
- $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_pay_rs['order_id'].'&st=2&bt=CHECK_SAVESUCCESS';
- }
- if ("3" == $_pay_rs['status']) {
- $_msg = "支付失败!";
- $this->assign('msg', $_msg);
- if (!empty($_apple_id)) {
- $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_pay_rs['order_id'].'&bt=CHECK_SAVEFAILED&st=1';
- }
- $this->assign('return_url', $_return_token);
- return $this->fetch('order/failed');
- }
- $this->assign('msg', $_msg);
- $this->assign('return_url', $_return_token);
- return $this->fetch('order/success');
- }
- /**
- * 支付宝支付显示地址
- * alipay/show
- *
- * @return mixed
- */
- public function showUrl() {
- $_order_id = $this->request->param('order_id/s', '');
- $_apple_id = $this->request->param('apple_id/s', '');
- $_return_token = '';
- if (!empty($_apple_id)) {
- $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_order_id.'&bt=CHECK_SAVEFAILED&st=1';
- }
- $this->assign('return_url', $_return_token);
- if (empty($_order_id)) {
- $_msg = '未支付';
- $this->assign('msg', $_msg);
- return $this->fetch('order/failed');
- }
- $_msg = '玩家取消支付,请重新下单';
- $this->assign('msg', $_msg);
- return $this->fetch('order/failed');
- }
- /**
- * IOS支付切换 支付url
- */
- public function submitUrl() {
- $_order_id = $this->request->param('order_id/s', '');
- $_pay_token = $this->request->param('pay_token/s', '');
- $_apple_id = $this->request->param('apple_id/s', '');
- $_pay_data = SdkPayCache::ins()->getInfoByOrderId($_order_id);
- $_return_token = '';
- if (empty($_apple_id)) {
- $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_order_id.'&bt=CHECK_SAVEFAILED&st=1';
- }
- if (empty($_order_id) || empty($_pay_token)) {
- $_msg = "亲,您支付失败了,请点击关闭按钮重试!";
- $this->assign('return_url', $_return_token);
- $this->assign('msg', $_msg);
- return $this->fetch('order/submit');
- }
- if ($_pay_token != $_pay_data['pay_token']) {
- $_msg = "亲,您支付失败了,请点击关闭按钮重试!";
- $this->assign('return_url', $_return_token);
- $this->assign('msg', $_msg);
- return $this->fetch('order/submit');
- }
- $_html = $_pay_data['token'];
- $_html = $_html."<script>document.forms['alipaysubmit'].submit();</script>";
- echo $_html;
- exit;
- }
- }
|