Crmeb.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services\serve\storage;
  12. use crmeb\basic\BaseStorage;
  13. use crmeb\services\AccessTokenServeService;
  14. use think\exception\ValidateException;
  15. /**
  16. * Class Crmeb
  17. * @package crmeb\services\serve\storage
  18. */
  19. class Crmeb extends BaseStorage
  20. {
  21. protected $accessToken;
  22. /**
  23. * Crmeb constructor.
  24. * @param string $name
  25. * @param AccessTokenServeService $service
  26. * @param string|null $configFile
  27. */
  28. public function __construct(string $name, AccessTokenServeService $service, string $configFile = null)
  29. {
  30. $this->accessToken = $service;
  31. }
  32. /**
  33. * 获取用户信息
  34. * @param string $account
  35. * @param string $secret
  36. * @return array|mixed
  37. */
  38. public function getUser()
  39. {
  40. return $this->accessToken->httpRequest('user/info');
  41. }
  42. /**
  43. * 用户登录
  44. * @param string $account
  45. * @param string $secret
  46. * @return array|mixed
  47. */
  48. public function login(string $account, string $secret)
  49. {
  50. return $this->accessToken->httpRequest('user/login', ['account' => $account, 'secret' => $secret], 'POST', false);
  51. }
  52. /**
  53. * 注册平台
  54. * @param array $data
  55. * @return array|mixed
  56. */
  57. public function register(array $data)
  58. {
  59. return $this->accessToken->httpRequest('user/register', $data, 'POST', false);
  60. }
  61. /**
  62. * 平台用户消息记录
  63. * @param int $page
  64. * @param int $limit
  65. * @return array|mixed
  66. */
  67. public function userBill(int $page, int $limit)
  68. {
  69. return $this->accessToken->httpRequest('user/bill', ['page' => $page, 'limit' => $limit]);
  70. }
  71. /**
  72. * 找回账号
  73. * @param array $data
  74. * @return array|mixed
  75. */
  76. public function forget(array $data)
  77. {
  78. return $this->accessToken->httpRequest('user/forget', $data, 'POST', false);
  79. }
  80. /**
  81. * 修改密码
  82. * @param array $data
  83. * @return array|mixed
  84. */
  85. public function modify(array $data)
  86. {
  87. return $this->accessToken->httpRequest('user/modify', $data, 'POST', false);
  88. }
  89. /**
  90. * 获取验证码
  91. * @param string $phone
  92. * @return array|mixed
  93. */
  94. public function code(string $phone, $type = 0)
  95. {
  96. return $this->accessToken->httpRequest('user/code', ['phone' => $phone, 'types' => $type], 'POST', false);
  97. }
  98. /**
  99. * 验证验证码
  100. * @param string $phone
  101. * @return array|mixed
  102. */
  103. public function checkCode(string $phone, string $verify_code)
  104. {
  105. return $this->accessToken->httpRequest('user/code/verify', ['phone' => $phone, 'verify_code' => $verify_code], 'POST', false);
  106. }
  107. /**
  108. * 套餐列表
  109. * @param string $type 套餐类型:sms,短信;query,物流查询;dump,电子面单;copy,产品复制
  110. * @return array|mixed
  111. */
  112. public function mealList(string $type)
  113. {
  114. return $this->accessToken->httpRequest('meal/list', ['type' => $type]);
  115. }
  116. /**
  117. * 套餐支付
  118. * @param array $data
  119. * @return array|mixed
  120. */
  121. public function payMeal(array $data)
  122. {
  123. return $this->accessToken->httpRequest('meal/code', $data);
  124. }
  125. /**
  126. * 用量记录
  127. * @param int $page
  128. * @param int $limit
  129. * @param int $type
  130. * @return array|mixed
  131. */
  132. public function record(int $page, int $limit, int $type, $status = '')
  133. {
  134. $typeContent = [1 => 'sms', 2 => 'expr_dump', 3 => 'expr_query', 4 => 'copy'];
  135. if (!isset($typeContent[$type])) {
  136. throw new ValidateException('参数类型不正确');
  137. }
  138. $data = ['page' => $page, 'limit' => $limit, 'type' => $typeContent[$type]];
  139. if ($type == 1 && $status != '') {
  140. $data['status'] = $status;
  141. }
  142. return $this->accessToken->httpRequest('user/record', $data);
  143. }
  144. /**
  145. * 修改手机号
  146. * @param array $data
  147. * @return array|mixed
  148. */
  149. public function modifyPhone(array $data)
  150. {
  151. return $this->accessToken->httpRequest('user/modify/phone', $data);
  152. }
  153. protected function initialize(array $config)
  154. {
  155. }
  156. }