123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
- /**
- * WappayController.php UTF-8
- *
- *
- * @date : 2018/3/17 16:26
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace api\sdk\controller;
- use api\common\controller\V2ApiBaseController;
- use huo\controller\common\HuoSession;
- use huo\controller\pay\GamePay;
- use huo\controller\pay\PtbPay;
- use huo\controller\pay\SdkOrderCache;
- use huo\controller\pay\SdkPayCache;
- use huolib\constant\CommonConst;
- use huolib\constant\DeviceTypeConst;
- use huolib\constant\GameConst;
- use huolib\constant\OrderConst;
- use huolib\constant\PaywayConst;
- use huolib\pay\Pay;
- use huolib\status\OrderStatus;
- use huolib\utils\OrderUtils;
- class ClientpayController extends V2ApiBaseController {
- function _initialize() {
- parent::_initialize();
- }
- /**
- * 选择支付页面支付
- * http://doc.1tsdk.com/138?page_id=3151
- *【域名】/wap/pay/post
- *
- */
- public function pay() {
- $this->checkLogin();
- $_order_id = get_val($this->rq_data, 'order_id');
- $_client = get_val($this->rq_data, 'client');
- $_game_rq = $this->setGameData();
- if (!empty($_order_id)) {
- $this->rq_data['order']['order_id'] = $_order_id;
- }
- $_order_rq = $this->setOrderData();
- $_device_rq = $this->setDeviceData();
- $_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);
- }
- /* 判断是否使用平台币 */
- $_has_ptb = get_val($this->rq_data, 'has_ptb', 2);
- if (OrderConst::PAY_HAS_PTB == $_has_ptb) {
- /* 使用平台币 先记录入缓存 */
- $_rdata = (new PtbPay())->PtbOrder($_order_rq->getOrderId());
- if (OrderStatus::NO_ERROR != $_rdata['code']) {
- $this->returnData($_rdata);
- }
- }
- $_order_data = SdkOrderCache::ins()->getInfoByOrderId($_order_rq->getOrderId());
- if ($_order_data['real_amount'] <= CommonConst::CONST_ZERO_COMPARE) {
- /* 完全使用平台币支付 */
- $_rs = (new PtbPay())->ptbSdkPay($_order_rq->getOrderId());
- $this->returnData($_rs);
- }
- /* 游戏币消费 特有流程 */
- if (PaywayConst::PAYWAY_GAMEPAY == strtolower($_payway)) {
- $_rs = (new GamePay())->GameSdkPay($_order_rq->getOrderId());
- $this->returnData($_rs);
- }
- 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);
- /*微信支付 走 mobilepay*/
- if (PaywayConst::PAYWAY_WXPAY == $_payway) {
- $_func = 'mobilePay';
- }
- $_show_url = url(
- 'sdk/'.$_payway.'/showUrl', ['order_id' => $_order_rq->getOrderId(), 'apple_id' => $_game_rq->getAppleId()],
- false, APISITE
- );
- $_return_url = url(
- 'sdk/'.$_payway.'/returnUrl',
- ['order_id' => $_order_rq->getOrderId(), 'apple_id' => $_game_rq->getAppleId()], 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, $_game_rq->getHAppId()))->getOpenId());
- if (GameConst::GAME_IOS_SWITCH == $_device_rq->getFrom()) {
- $_pay_rs = $_pay_class->mobilePay();
- /*
- $_pay_data['token'] = $_pay_rs['token'];
- $_pay_data['pay_token'] = $_order_rq->genPayToken($_order_id);
- SdkPayCache::ins()->saveOrderCache($_order_rq->getOrderId(), $_pay_data); //存缓存
- $_pay_rs['token'] = url(
- 'sdk/'.$_payway.'/submitUrl',
- ['order_id' => $_order_rq->getOrderId(), 'pay_token' => $_pay_data['pay_token']], false, APISITE
- );*/
- } else {
- $_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);
- if (PaywayConst::PAYWAY_WXPAY == $_payway) {
- $_pay_data = [];
- $_pay_data['token'] = $_pay_rs['token'];
- SdkPayCache::ins()->saveOrderCache($_order_rq->getOrderId(), $_pay_data); //存缓存
- $_pay_rs['token'] = url(
- 'sdk/'.$_payway.'/payUrl', ['order_id' => $_order_rq->getOrderId()], false, APISITE
- );
- }
- $_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;
- }
- }
|