* @version : HUOSDK 8.0 */ namespace api\apple\controller; use api\common\controller\AppleApiBaseController; use huo\controller\common\HuoSession; use huo\controller\member\Member; use huo\controller\member\MemCache; use huo\controller\pay\PtbPay; use huo\controller\pay\SdkOrderCache; use huolib\constant\DeviceTypeConst; use huolib\constant\PaywayConst; use huolib\pay\Pay; use huolib\status\OrderStatus; use huolib\utils\OrderUtils; class WappayController extends AppleApiBaseController { function _initialize() { parent::_initialize(); } /** * 选择支付页面支付 * http://doc.1tsdk.com/138?page_id=3151 *【域名】/wap/pay/post * */ public function pay() { $this->checkLogin(); $_mc_class = MemCache::ins(); $_mem_data = $_mc_class->getInfoById($this->mem_id); $_order_id = get_val($this->rq_data, 'order_id', ''); if (!empty($_order_id)) { $this->rq_data['order']['order_id'] = $_order_id; } $_order_rq = $this->setOrderData(); $_pay_token = get_val($this->rq_data, 'pay_token', ''); $_rs = $_order_rq->checkPayToken($_pay_token); if (false == $_rs) { $_code = OrderStatus::TOKEN_ARGS_ERROR; // $this->error(OrderStatus::getMsg($_code), [], $_code); } $_payway = get_val($this->rq_data, 'payway', ''); $_pw_check_rs = OrderUtils::checkPayway($_payway); if (OrderStatus::NO_ERROR != $_pw_check_rs) { $this->error(OrderStatus::getMsg($_pw_check_rs), [], $_pw_check_rs); } /* 平台币 游戏币消费 特有流程 */ if (PaywayConst::PAYWAY_PTBPAY == strtolower($_payway)) { $_rs = (new PtbPay())->ptbSdkPay($_order_rq->getOrderId()); $this->returnData($_rs); } $_order_data = SdkOrderCache::ins()->getInfoByOrderId($_order_rq->getOrderId()); if (empty($_order_data)) { $_code = OrderStatus::ORDER_NOT_EXISTS; $this->error(OrderStatus::getMsg($_code), [], $_code); } $_order_rq->setDataFromOrder($_order_data); $_pay_class = Pay::ins()->get($_payway); $_func = $this->getFunc($this->device_type); $_show_url = url('sdk/'.$_payway.'/showUrl', ['order_id' => $_order_rq->getOrderId()], false, APISITE); $_return_url = url( 'sdk/'.$_payway.'/returnUrl', ['order_id' => $_order_rq->getOrderId()], false, APISITE ); $_notify_url = url('sdk/'.$_payway.'/notifyUrl', '', false, APISITE); $_pay_class->setNotifyUrl($_notify_url); $_pay_class->setReturnUrl($_return_url); $_pay_class->setShowUrl($_show_url); $_pay_class->setOrderId($_order_rq->getOrderId()); $_pay_class->setProductName($_order_rq->getProductName()); $_pay_class->setProductDesc($_order_rq->getProductDesc()); $_pay_class->setRealAmount($_order_rq->getProductRealPrice()); $_pay_class->setProductPrice($_order_rq->getProductPrice()); $_pay_class->setProductId($_order_rq->getProductId()); $_pay_class->setIp($this->request->ip()); $_pay_class->setOpenId((new HuoSession($this->mem_id))->getOpenId()); $_pay_class->setMemId($this->mem_id); $_pay_class->setMemRealName($_mem_data['real_name']); $_pay_class->setMemRegTime($_mem_data['create_time']); $_pay_class->setMemMobile($_mem_data['mobile']); $_pay_rs = $_pay_class->$_func(); if (empty($_pay_rs)) { $_code = OrderStatus::PAYWAY_PREORDER_ERROR; $this->error(OrderStatus::getMsg($_code), [], $_code); } /* 更新支付方式 */ $_pay_alias = $_pay_rs['pay_type']; $_order_data['payway'] = $_pay_alias; SdkOrderCache::ins()->updateOrder($_order_rq->getOrderId(), $_order_data); $_code = OrderStatus::NO_ERROR; $this->success(OrderStatus::getMsg($_code), $_pay_rs, $_code); } /** * @param $device_type * * @return string clientPay mobilePay pcPay */ public function getFunc($device_type) { switch ($device_type) { case DeviceTypeConst::DEVICE_TYPE_IOSAPPLESDK: $_type = 'clientPay'; break; case DeviceTypeConst::DEVICE_TYPE_IOSSDK: $_type = 'clientPay'; break; case DeviceTypeConst::DEVICE_TYPE_IOSAPP: $_type = 'clientPay'; break; case DeviceTypeConst::DEVICE_TYPE_IOSH5APP: $_type = 'clientPay'; break; case DeviceTypeConst::DEVICE_TYPE_SAFARI: $_type = 'mobilePay'; break; case DeviceTypeConst::DEVICE_TYPE_ANDSDK: $_type = 'clientPay'; break; case DeviceTypeConst::DEVICE_TYPE_ANDAPP: $_type = 'clientPay'; break; case DeviceTypeConst::DEVICE_TYPE_ANDH5APP: $_type = 'clientPay'; break; case DeviceTypeConst::DEVICE_TYPE_ANDBROWSER: $_type = 'mobilePay'; break; case DeviceTypeConst::DEVICE_TYPE_WEIXIN: $_type = 'jsPay'; break; case DeviceTypeConst::DEVICE_TYPE_PC: $_type = 'pcPay'; break; case DeviceTypeConst::DEVICE_TYPE_WAP: $_type = 'mobilePay'; break; default: $_type = 'mobilePay'; } return $_type; } }