Crmeb.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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. protected function initialize(array $config)
  33. {
  34. // TODO: Implement initialize() method.
  35. }
  36. /**
  37. * 获取用户信息
  38. * @param string $account
  39. * @param string $secret
  40. * @return array|mixed
  41. */
  42. public function getUser()
  43. {
  44. return $this->accessToken->httpRequest('user/info');
  45. }
  46. /**
  47. * 用户登录
  48. * @param string $account
  49. * @param string $secret
  50. * @return array|mixed
  51. */
  52. public function login(string $account, string $secret)
  53. {
  54. return $this->accessToken->httpRequest('user/login', ['account' => $account, 'secret' => $secret], 'POST', false);
  55. }
  56. /**
  57. * 注册平台
  58. * @param array $data
  59. * @return array|mixed
  60. */
  61. public function register(array $data)
  62. {
  63. return $this->accessToken->httpRequest('user/register', $data, 'POST', false);
  64. }
  65. /**
  66. * 平台用户消息记录
  67. * @param int $page
  68. * @param int $limit
  69. * @return array|mixed
  70. */
  71. public function userBill(int $page, int $limit)
  72. {
  73. return $this->accessToken->httpRequest('user/bill', ['page' => $page, 'limit' => $limit]);
  74. }
  75. /**
  76. * 找回账号
  77. * @param array $data
  78. * @return array|mixed
  79. */
  80. public function forget(array $data)
  81. {
  82. return $this->accessToken->httpRequest('user/forget', $data, 'POST', false);
  83. }
  84. /**
  85. * 修改密码
  86. * @param array $data
  87. * @return array|mixed
  88. */
  89. public function modify(array $data)
  90. {
  91. return $this->accessToken->httpRequest('user/modify', $data, 'POST', false);
  92. }
  93. /**
  94. * 获取验证码
  95. * @param string $phone
  96. * @return array|mixed
  97. */
  98. public function code(string $phone, $type = 0)
  99. {
  100. return $this->accessToken->httpRequest('user/code', ['phone' => $phone, 'types' => $type], 'POST', false);
  101. }
  102. /**
  103. * 验证验证码
  104. * @param string $phone
  105. * @return array|mixed
  106. */
  107. public function checkCode(string $phone, string $verify_code)
  108. {
  109. return $this->accessToken->httpRequest('user/code/verify', ['phone' => $phone, 'verify_code' => $verify_code], 'POST', false);
  110. }
  111. /**
  112. * 套餐列表
  113. * @param string $type 套餐类型:sms,短信;query,物流查询;dump,电子面单;copy,产品复制
  114. * @return array|mixed
  115. */
  116. public function mealList(string $type)
  117. {
  118. return $this->accessToken->httpRequest('meal/list', ['type' => $type]);
  119. }
  120. /**
  121. * 套餐支付
  122. * @param array $data
  123. * @return array|mixed
  124. */
  125. public function payMeal(array $data)
  126. {
  127. return $this->accessToken->httpRequest('meal/code', $data);
  128. }
  129. /**
  130. * 用量记录
  131. * @param int $page
  132. * @param int $limit
  133. * @param int $type
  134. * @return array|mixed
  135. */
  136. public function record(int $page, int $limit, int $type, $status = '')
  137. {
  138. $typeContent = [1 => 'sms', 2 => 'expr_dump', 3 => 'expr_query', 4 => 'copy'];
  139. if (!isset($typeContent[$type])) {
  140. throw new ValidateException('参数类型不正确');
  141. }
  142. $data = ['page' => $page, 'limit' => $limit, 'type' => $typeContent[$type]];
  143. return $this->accessToken->httpRequest('user/record', $data);
  144. }
  145. /**
  146. * 修改手机号
  147. * @param array $data
  148. * @return array|mixed
  149. */
  150. public function modifyPhone(array $data)
  151. {
  152. return $this->accessToken->httpRequest('user/modify/phone', $data);
  153. }
  154. }