ApplePayQueue.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * ApplePayQueue.php UTF-8
  4. * 苹果支付队列
  5. *
  6. * @date : 2018/6/11 19:58
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\queue;
  13. use huo\controller\common\Base;
  14. use huolib\queue\constant\ClassConst;
  15. use huolib\queue\constant\JobConst;
  16. use huolib\status\CommonStatus;
  17. use think\Queue;
  18. class ApplePayQueue extends Base {
  19. protected $param = [];
  20. protected $job_class = '';
  21. protected $job_name = '';
  22. public function __construct($apple_id = '') {
  23. $this->job_class = ClassConst::CLASS_APPLE_PAY_FIRE;
  24. $this->job_name = JobConst::JOB_APPLE_PAY;
  25. $this->param['ts'] = time();
  26. $this->setAppleId($apple_id);
  27. }
  28. /**
  29. * 返回数据
  30. *
  31. * @param int $code
  32. * @param array $data
  33. *
  34. * @return array
  35. */
  36. protected function retSucMsg($code = CommonStatus::NO_ERROR, $data = []) {
  37. /* 数据录入LOG */
  38. $this->param['queue'] = '1';
  39. return $this->huoSuccess($code, '', $data);
  40. }
  41. /**
  42. * 返回数据
  43. *
  44. * @param $code
  45. *
  46. * @return array|mixed
  47. */
  48. protected function retErrMsg($code = CommonStatus::PUSH_QUEUE_ERROR) {
  49. /* 数据录入LOG */
  50. $this->param['queue'] = '0';
  51. return $this->huoError($code);
  52. }
  53. public function setApplePayQueue(
  54. $order_id, $trans_id, $receipt_data = null, $is_sandbox = false, $idfv = '', $apple_id = ''
  55. ) {
  56. $this->setOrderId($order_id);
  57. $this->setTransId($trans_id);
  58. $this->setReceiptData($receipt_data);
  59. $this->setIsSandbox($is_sandbox);
  60. $this->setIdfv($idfv);
  61. $this->setAppleId($apple_id);
  62. return $this->pushQueue();
  63. }
  64. /**
  65. * 入队列
  66. *
  67. * @return array
  68. */
  69. protected function pushQueue() {
  70. if (class_exists('think\\Queue')) {
  71. $_is_pushed = Queue::push($this->job_class, $this->param, $this->job_name);
  72. if ($_is_pushed !== false) {
  73. return $this->retErrMsg();
  74. }
  75. }
  76. return $this->retSucMsg();
  77. }
  78. /**
  79. * 设置平台订单ID
  80. *
  81. * @param string $order_id 平台订单ID
  82. */
  83. public function setOrderId($order_id) {
  84. $this->param['order_id'] = $order_id;
  85. }
  86. /**
  87. * 设置苹果订单ID
  88. *
  89. * @param string $trans_id 苹果订单ID
  90. */
  91. public function setTransId($trans_id) {
  92. $this->param['trans_id'] = $trans_id;
  93. }
  94. /**
  95. * 设置苹果支付票据
  96. *
  97. * @param string $receipt_data 苹果支付票据
  98. */
  99. public function setReceiptData($receipt_data) {
  100. $this->param['receipt_data'] = $receipt_data;
  101. }
  102. /**
  103. * 设置是否沙盒环境
  104. *
  105. * @param bool $is_sandbox 是否是沙盒环境
  106. */
  107. public function setIsSandbox($is_sandbox) {
  108. $this->param['is_sandbox'] = $is_sandbox;
  109. }
  110. /**
  111. * 设置IDFV
  112. *
  113. * @param string $idfv 苹果IDFV
  114. */
  115. public function setIdfv($idfv) {
  116. $this->param['idfv'] = $idfv;
  117. }
  118. /**
  119. * 设置苹果应用ID
  120. *
  121. * @param string $apple_id 苹果应用ID
  122. */
  123. public function setAppleId($apple_id) {
  124. $this->param['apple_id'] = $apple_id;
  125. }
  126. /**
  127. * @return string
  128. */
  129. public function getJobClass() {
  130. return $this->job_class;
  131. }
  132. /**
  133. * @param string $job_class
  134. */
  135. public function setJobClass($job_class) {
  136. $this->job_class = $job_class;
  137. }
  138. /**
  139. * @return string
  140. */
  141. public function getJobName() {
  142. return $this->job_name;
  143. }
  144. /**
  145. * @param string $job_name
  146. */
  147. public function setJobName($job_name) {
  148. $this->job_name = $job_name;
  149. }
  150. }