CoreApi.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace addons\AvoidTax\common\jdk\xinlong;
  3. use Exception;
  4. /**
  5. * CoreApi
  6. * @package addons\AvoidTax\common\jdk\xinlong
  7. */
  8. class CoreApi extends BaseApi
  9. {
  10. const TOKEN_KEY = "avoid_tax:xinlong:token";
  11. protected $mall_id;
  12. public function __construct($mall_id, $config = [])
  13. {
  14. $this->mall_id = $mall_id;
  15. if (empty($config)) {
  16. parent::__construct([]);
  17. } else {
  18. foreach ($config as $key => $val) {
  19. if (property_exists($this, $key)) {
  20. $this->{$key} = $val;
  21. }
  22. }
  23. }
  24. // parent::__construct($config);
  25. $this->getToken();
  26. }
  27. public function getRedisKey()
  28. {
  29. return self::TOKEN_KEY . $this->mall_id;
  30. }
  31. /**
  32. * 初始化token
  33. *
  34. * @return string
  35. */
  36. public function getToken()
  37. {
  38. $token = \Yii::$app->redis->get($this->getRedisKey());
  39. if (!empty($token)) {
  40. return $token;
  41. }
  42. $token = $this->queryToken();
  43. if (!isset($token['access_token'])) {
  44. throw new Exception("获取 token 失败");
  45. }
  46. \Yii::$app->redis->setex($this->getRedisKey(), $token['expires_in'] - 600, $token['access_token']);
  47. return $token['access_token'];
  48. }
  49. /**
  50. * 创建签约
  51. *
  52. * @param string $mobile
  53. * @param string $idNumber
  54. * @param string $realname
  55. * @return array
  56. */
  57. public function submitCreateUser($mobile, $idNumber, $realname)
  58. {
  59. return $this->requestPost(__FUNCTION__, compact('mobile', 'idNumber', 'realname'));
  60. }
  61. /**
  62. * 电子签约
  63. *
  64. * @param integer $accountId
  65. * @param string $notify_url
  66. * @param string $redirect_url
  67. * @return array
  68. */
  69. public function submitSign($accountId, $notify_url = '', $redirect_url = '')
  70. {
  71. return $this->requestPost(__FUNCTION__, compact('accountId', 'notify_url', 'redirect_url'));
  72. }
  73. /**
  74. * 签约查询
  75. *
  76. * @param string $mobile
  77. * @param string $idNumber
  78. * @param string $realname
  79. * @return array
  80. */
  81. public function getEsign($mobile, $idNumber, $realname)
  82. {
  83. return $this->requestPost(__FUNCTION__, compact('mobile', 'idNumber', 'realname'));
  84. }
  85. /**
  86. * 风控接口(提交订单)
  87. *
  88. * @param array $order
  89. * @return array
  90. */
  91. public function getRiskControl($order)
  92. {
  93. return $this->requestPost(__FUNCTION__, $order);
  94. }
  95. /**
  96. * 支付完成后给税务方发送推送
  97. *
  98. * @param array $order
  99. * @return array
  100. */
  101. public function withdrawOrder($order)
  102. {
  103. return $this->requestPost(__FUNCTION__, $order);
  104. }
  105. }