| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace addons\AvoidTax\common\jdk\xinlong;
- use Exception;
- /**
- * CoreApi
- * @package addons\AvoidTax\common\jdk\xinlong
- */
- class CoreApi extends BaseApi
- {
- const TOKEN_KEY = "avoid_tax:xinlong:token";
- protected $mall_id;
- public function __construct($mall_id, $config = [])
- {
- $this->mall_id = $mall_id;
- if (empty($config)) {
- parent::__construct([]);
- } else {
- foreach ($config as $key => $val) {
- if (property_exists($this, $key)) {
- $this->{$key} = $val;
- }
- }
- }
- // parent::__construct($config);
- $this->getToken();
- }
- public function getRedisKey()
- {
- return self::TOKEN_KEY . $this->mall_id;
- }
- /**
- * 初始化token
- *
- * @return string
- */
- public function getToken()
- {
- $token = \Yii::$app->redis->get($this->getRedisKey());
- if (!empty($token)) {
- return $token;
- }
- $token = $this->queryToken();
- if (!isset($token['access_token'])) {
- throw new Exception("获取 token 失败");
- }
- \Yii::$app->redis->setex($this->getRedisKey(), $token['expires_in'] - 600, $token['access_token']);
- return $token['access_token'];
- }
- /**
- * 创建签约
- *
- * @param string $mobile
- * @param string $idNumber
- * @param string $realname
- * @return array
- */
- public function submitCreateUser($mobile, $idNumber, $realname)
- {
- return $this->requestPost(__FUNCTION__, compact('mobile', 'idNumber', 'realname'));
- }
- /**
- * 电子签约
- *
- * @param integer $accountId
- * @param string $notify_url
- * @param string $redirect_url
- * @return array
- */
- public function submitSign($accountId, $notify_url = '', $redirect_url = '')
- {
- return $this->requestPost(__FUNCTION__, compact('accountId', 'notify_url', 'redirect_url'));
- }
- /**
- * 签约查询
- *
- * @param string $mobile
- * @param string $idNumber
- * @param string $realname
- * @return array
- */
- public function getEsign($mobile, $idNumber, $realname)
- {
- return $this->requestPost(__FUNCTION__, compact('mobile', 'idNumber', 'realname'));
- }
-
- /**
- * 风控接口(提交订单)
- *
- * @param array $order
- * @return array
- */
- public function getRiskControl($order)
- {
- return $this->requestPost(__FUNCTION__, $order);
- }
-
- /**
- * 支付完成后给税务方发送推送
- *
- * @param array $order
- * @return array
- */
- public function withdrawOrder($order)
- {
- return $this->requestPost(__FUNCTION__, $order);
- }
- }
|