* @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\constant\CommonConst; use huolib\constant\OrderConst; use huolib\pay\Pay; use think\Config; class WxpayController extends V2ApiBaseController { function _initialize() { parent::_initialize(); \think\Log::write($this->request->getContent(), 'error'); Config::set('default_return_type', 'html'); } /** * 微信支付回调地址 * wxpay/notify */ public function notifyUrl() { $_xml = file_get_contents('php://input'); $_REQUEST = $this->xmlToArray($_xml); $_class = new Notify(); $_product_id = get_val($_REQUEST, 'attach', ''); $_order_id = get_val($_REQUEST, 'out_trade_no', ''); $_class->notifyUrl('wxpay', $_product_id, 0, $_order_id); } /** * 微信支付通知地址 * wxpay/return * * @return mixed * @throws \think\Exception */ public function returnUrl() { $_pay_class = Pay::ins()->get('wxpay'); $_pay_class->setPayway('Wxpay'); $_order_id = $this->request->param('order_id/s', ''); $_apple_id = $this->request->param('apple_id/s', ''); $_return_token = ''; if (empty($_order_id)) { $_msg = "参数错误!"; $this->assign('return_url', $_return_token); $this->assign('msg', $_msg); $this->assign('failed', 1); return $this->fetch('order/success'); } $_order_info = SdkOrderCache::ins()->getInfoByOrderId($_order_id); $_app_id = get_val($_order_info, 'app_id', CommonConst::CONST_ZERO); $_config = (new PaywayConf())->getConfByAppPayway($_app_id, 'wxpay'); $_ext = ['config' => $_config]; $_pay_rs = $_pay_class->orderQuery($_order_id, '', $_ext); $_failed = 1; $_st = 1; $_bt = 'CHECK_SAVEFAILED'; if (false == $_pay_rs) { $_msg = "支付失败!"; } else { switch ($_pay_rs) { case OrderConst::WXPAY_STATUS_SUCCESS: $_msg = '支付成功'; $_failed = 0; $_bt = 'CHECK_SAVESUCCESS'; $_st = 2; break; case OrderConst::WXPAY_STATUS_REFUND: $_msg = '转入退款'; break; case OrderConst::WXPAY_STATUS_NOTPAY: $_msg = '未支付'; break; case OrderConst::WXPAY_STATUS_CLOSED: $_msg = '已关闭'; break; case OrderConst::WXPAY_STATUS_REVOKED: $_msg = '已撤销'; break; case OrderConst::WXPAY_STATUS_USERPAYING: $_msg = '支付中'; break; default: $_msg = '支付失败'; } } if (!empty($_apple_id)) { //$_return_token = 'htsdk.com633403350://qo?oi='.$_order_id.'&bt=1&st='.$_st; $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_order_id.'&bt='.$_bt.'&st='.$_st; } $this->assign('msg', $_msg); $this->assign('return_url', $_return_token); if ($_failed) { return $this->fetch('order/failed'); } return $this->fetch('order/success'); } /** * 微信支付显示地址 * wxpay/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'); } /** * 将xml转为array */ public function xmlToArray($xml) { $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $array_data; } /** * IOS支付切换 支付url */ public function submit() { $_order_id = $this->request->param('order_id/s', ''); $_apple_id = $this->request->param('apple_id/s', ''); $_pay_token = $this->request->param('pay_token/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']) { $this->assign('return_url', $_return_token); $_msg = "亲,您支付失败了,请点击关闭按钮重试!"; $this->assign('msg', $_msg); return $this->fetch('order/submit'); } $this->assign('token', $_pay_data['token']); $this->assign('return_url', $_return_token); $this->assign( 'query_url', SDKSITE.url('Pay/Wxpay/checkurl', array('order_id' => $_order_id)) ); return $this->fetch('order/wxsubmit'); } /** * 自动支付 */ public function payUrl() { $_order_id = $this->request->param('order_id/s', ''); if (empty($_order_id)) { $this->error('订单号错误'); } $_pay_data = SdkPayCache::ins()->getInfoByOrderId($_order_id); if (empty($_pay_data) || empty($_pay_data['token'])) { $this->error('支付参数错误'); } echo ""; } }