WappayController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * WappayController.php UTF-8
  4. *
  5. *
  6. * @date : 2018/3/17 16:26
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace api\apple\controller;
  13. use api\common\controller\AppleApiBaseController;
  14. use huo\controller\common\HuoSession;
  15. use huo\controller\member\Member;
  16. use huo\controller\member\MemCache;
  17. use huo\controller\pay\PtbPay;
  18. use huo\controller\pay\SdkOrderCache;
  19. use huolib\constant\DeviceTypeConst;
  20. use huolib\constant\PaywayConst;
  21. use huolib\pay\Pay;
  22. use huolib\status\OrderStatus;
  23. use huolib\utils\OrderUtils;
  24. class WappayController extends AppleApiBaseController {
  25. function _initialize() {
  26. parent::_initialize();
  27. }
  28. /**
  29. * 选择支付页面支付
  30. * http://doc.1tsdk.com/138?page_id=3151
  31. *【域名】/wap/pay/post
  32. *
  33. */
  34. public function pay() {
  35. $this->checkLogin();
  36. $_mc_class = MemCache::ins();
  37. $_mem_data = $_mc_class->getInfoById($this->mem_id);
  38. $_order_id = get_val($this->rq_data, 'order_id', '');
  39. if (!empty($_order_id)) {
  40. $this->rq_data['order']['order_id'] = $_order_id;
  41. }
  42. $_order_rq = $this->setOrderData();
  43. $_pay_token = get_val($this->rq_data, 'pay_token', '');
  44. $_rs = $_order_rq->checkPayToken($_pay_token);
  45. if (false == $_rs) {
  46. $_code = OrderStatus::TOKEN_ARGS_ERROR;
  47. // $this->error(OrderStatus::getMsg($_code), [], $_code);
  48. }
  49. $_payway = get_val($this->rq_data, 'payway', '');
  50. $_pw_check_rs = OrderUtils::checkPayway($_payway);
  51. if (OrderStatus::NO_ERROR != $_pw_check_rs) {
  52. $this->error(OrderStatus::getMsg($_pw_check_rs), [], $_pw_check_rs);
  53. }
  54. /* 平台币 游戏币消费 特有流程 */
  55. if (PaywayConst::PAYWAY_PTBPAY == strtolower($_payway)) {
  56. $_rs = (new PtbPay())->ptbSdkPay($_order_rq->getOrderId());
  57. $this->returnData($_rs);
  58. }
  59. $_order_data = SdkOrderCache::ins()->getInfoByOrderId($_order_rq->getOrderId());
  60. if (empty($_order_data)) {
  61. $_code = OrderStatus::ORDER_NOT_EXISTS;
  62. $this->error(OrderStatus::getMsg($_code), [], $_code);
  63. }
  64. $_order_rq->setDataFromOrder($_order_data);
  65. $_pay_class = Pay::ins()->get($_payway);
  66. $_func = $this->getFunc($this->device_type);
  67. $_show_url = url('sdk/'.$_payway.'/showUrl', ['order_id' => $_order_rq->getOrderId()], false, APISITE);
  68. $_return_url = url(
  69. 'sdk/'.$_payway.'/returnUrl', ['order_id' => $_order_rq->getOrderId()], false, APISITE
  70. );
  71. $_notify_url = url('sdk/'.$_payway.'/notifyUrl', '', false, APISITE);
  72. $_pay_class->setNotifyUrl($_notify_url);
  73. $_pay_class->setReturnUrl($_return_url);
  74. $_pay_class->setShowUrl($_show_url);
  75. $_pay_class->setOrderId($_order_rq->getOrderId());
  76. $_pay_class->setProductName($_order_rq->getProductName());
  77. $_pay_class->setProductDesc($_order_rq->getProductDesc());
  78. $_pay_class->setRealAmount($_order_rq->getProductRealPrice());
  79. $_pay_class->setProductPrice($_order_rq->getProductPrice());
  80. $_pay_class->setProductId($_order_rq->getProductId());
  81. $_pay_class->setIp($this->request->ip());
  82. $_pay_class->setOpenId((new HuoSession($this->mem_id))->getOpenId());
  83. $_pay_class->setMemId($this->mem_id);
  84. $_pay_class->setMemRealName($_mem_data['real_name']);
  85. $_pay_class->setMemRegTime($_mem_data['create_time']);
  86. $_pay_class->setMemMobile($_mem_data['mobile']);
  87. $_pay_rs = $_pay_class->$_func();
  88. if (empty($_pay_rs)) {
  89. $_code = OrderStatus::PAYWAY_PREORDER_ERROR;
  90. $this->error(OrderStatus::getMsg($_code), [], $_code);
  91. }
  92. /* 更新支付方式 */
  93. $_pay_alias = $_pay_rs['pay_type'];
  94. $_order_data['payway'] = $_pay_alias;
  95. SdkOrderCache::ins()->updateOrder($_order_rq->getOrderId(), $_order_data);
  96. $_code = OrderStatus::NO_ERROR;
  97. $this->success(OrderStatus::getMsg($_code), $_pay_rs, $_code);
  98. }
  99. /**
  100. * @param $device_type
  101. *
  102. * @return string clientPay mobilePay pcPay
  103. */
  104. public function getFunc($device_type) {
  105. switch ($device_type) {
  106. case DeviceTypeConst::DEVICE_TYPE_IOSAPPLESDK:
  107. $_type = 'clientPay';
  108. break;
  109. case DeviceTypeConst::DEVICE_TYPE_IOSSDK:
  110. $_type = 'clientPay';
  111. break;
  112. case DeviceTypeConst::DEVICE_TYPE_IOSAPP:
  113. $_type = 'clientPay';
  114. break;
  115. case DeviceTypeConst::DEVICE_TYPE_IOSH5APP:
  116. $_type = 'clientPay';
  117. break;
  118. case DeviceTypeConst::DEVICE_TYPE_SAFARI:
  119. $_type = 'mobilePay';
  120. break;
  121. case DeviceTypeConst::DEVICE_TYPE_ANDSDK:
  122. $_type = 'clientPay';
  123. break;
  124. case DeviceTypeConst::DEVICE_TYPE_ANDAPP:
  125. $_type = 'clientPay';
  126. break;
  127. case DeviceTypeConst::DEVICE_TYPE_ANDH5APP:
  128. $_type = 'clientPay';
  129. break;
  130. case DeviceTypeConst::DEVICE_TYPE_ANDBROWSER:
  131. $_type = 'mobilePay';
  132. break;
  133. case DeviceTypeConst::DEVICE_TYPE_WEIXIN:
  134. $_type = 'jsPay';
  135. break;
  136. case DeviceTypeConst::DEVICE_TYPE_PC:
  137. $_type = 'pcPay';
  138. break;
  139. case DeviceTypeConst::DEVICE_TYPE_WAP:
  140. $_type = 'mobilePay';
  141. break;
  142. default:
  143. $_type = 'mobilePay';
  144. }
  145. return $_type;
  146. }
  147. }