CrmebPlatService.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * @author: zhypy<214681832@qq.com>
  4. * @day: 2020/10/15
  5. */
  6. namespace crmeb\services;
  7. class CrmebPlatService
  8. {
  9. /**
  10. * 验证码
  11. */
  12. const PLAT_CODE = 'user/code';
  13. /**
  14. * 平台注册
  15. */
  16. const PLAT_OPEN = 'user/register';
  17. /**
  18. * 用户信息
  19. */
  20. const PLAT_USER_INFO = 'user/info';
  21. /**
  22. * 修改密码
  23. */
  24. const PLAT_USER_MODIFY = 'user/modify';
  25. /**
  26. * 找回秘钥
  27. */
  28. const PLAT_USER_FORGET = 'user/forget';
  29. /**
  30. * 消费记录
  31. */
  32. const PLAT_BILL = 'user/bill';
  33. /**
  34. * 用量记录
  35. */
  36. const PlAT_RRCORD = 'user/record';
  37. /**
  38. * 套餐列表
  39. */
  40. const MEAL_LIST = 'meal/list';
  41. /**
  42. * 支付二维码
  43. */
  44. const MEAL_CODE = 'meal/code';
  45. /**
  46. * 账号
  47. * @var null
  48. */
  49. protected $account = NULL;
  50. /**
  51. * 秘钥
  52. * @var null
  53. */
  54. protected $sercet = NULL;
  55. /**
  56. * access_token
  57. * @var null
  58. */
  59. protected $accessToken = NULL;
  60. public function __construct($account = '', $sercet = '')
  61. {
  62. $this->accessToken = $this->getAccessToken($account, $sercet);
  63. }
  64. protected function getAccessToken($account, $sercet)
  65. {
  66. $this->account = $account ? $account : sys_config('sms_account');
  67. $this->sercet = $sercet ? $sercet : sys_config('sms_token');
  68. return new AccessTokenServeService($this->account, $this->sercet);
  69. }
  70. /**
  71. * 获取验证码
  72. * @param $phone
  73. * @return bool|mixed
  74. */
  75. public function code($phone)
  76. {
  77. $param = [
  78. 'phone' => $phone
  79. ];
  80. return $this->accessToken->httpRequest(self::PLAT_CODE, $param, 'POST', false);
  81. }
  82. /**
  83. * 注册
  84. * @param $account
  85. * @param $phone
  86. * @param $password
  87. * @param $verify_code
  88. * @return bool
  89. */
  90. public function register($account, $phone, $password, $verify_code)
  91. {
  92. $param = [
  93. 'account' => $account,
  94. 'phone' => $phone,
  95. 'password' => md5($password),
  96. 'verify_code' => $verify_code
  97. ];
  98. $result = $this->accessToken->httpRequest(self::PLAT_OPEN, $param, 'POST', false);
  99. return $result;
  100. }
  101. /**
  102. * 登录
  103. * @param $account
  104. * @param $secret
  105. * @return mixed
  106. */
  107. public function login($account, $secret)
  108. {
  109. $token = $this->getAccessToken($account, $secret)->getToken();
  110. return $token;
  111. }
  112. /**
  113. * 退出登录
  114. * @param $account
  115. * @param $secret
  116. * @return mixed
  117. */
  118. public function loginOut()
  119. {
  120. return $this->accessToken->destroyToken();
  121. }
  122. /**
  123. * 用户详情
  124. * @return mixed
  125. */
  126. public function info()
  127. {
  128. $result = $this->accessToken->httpRequest(self::PLAT_USER_INFO);
  129. return $result;
  130. }
  131. /**
  132. * 修改秘钥
  133. * @param $account
  134. * @param $phone
  135. * @param $password
  136. * @param $verify_code
  137. * @return bool
  138. */
  139. public function modify($account, $phone, $password, $verify_code)
  140. {
  141. $param = [
  142. 'account' => $account,
  143. 'phone' => $phone,
  144. 'password' => md5($password),
  145. 'verify_code' => $verify_code
  146. ];
  147. return $this->accessToken->httpRequest(self::PLAT_USER_MODIFY, $param, 'POST', false);
  148. }
  149. /**
  150. * 找回秘钥
  151. * @param $phone
  152. * @param $verify_code
  153. * @return mixed
  154. */
  155. public function forget($phone, $verify_code)
  156. {
  157. $param = [
  158. 'phone' => $phone,
  159. 'verify_code' => $verify_code
  160. ];
  161. $result = $this->accessToken->httpRequest(self::PLAT_USER_FORGET, $param, 'POST', false);
  162. return $result;
  163. }
  164. /**
  165. * 获取消费记录
  166. * @param int $page
  167. * @param int $limit
  168. * @return mixed
  169. */
  170. public function bill($page = 0, $limit = 10)
  171. {
  172. $param = [
  173. 'page' => $page,
  174. 'limit' => $limit
  175. ];
  176. $result = $this->accessToken->httpRequest(self::PLAT_BILL, $param);
  177. return $result;
  178. }
  179. /**
  180. * 获取用量记录
  181. * @param string $type
  182. * @param int $page
  183. * @param int $limit
  184. * @return array|mixed
  185. */
  186. public function record($type = 'sms', $page = 0, $limit = 10)
  187. {
  188. $param = [
  189. 'type' => $type,
  190. 'page' => $page,
  191. 'limit' => $limit
  192. ];
  193. $result = $this->accessToken->httpRequest(self::PlAT_RRCORD, $param);
  194. return $result;
  195. }
  196. /**
  197. * 套餐列表
  198. * @param string $type
  199. * @return array|bool|mixed
  200. */
  201. public function meal($type = 'sms')
  202. {
  203. $param = [
  204. 'type' => $type
  205. ];
  206. return $this->accessToken->httpRequest(self::MEAL_LIST, $param);
  207. }
  208. /**
  209. * 获取支付二维码
  210. * @param $type
  211. * @param $meal_id
  212. * @param $price
  213. * @param $num
  214. * @param string $pay_type
  215. * @return array|mixed
  216. */
  217. public function pay($type, $meal_id, $price, $num, $pay_type = 'weixin')
  218. {
  219. $param = [
  220. 'type' => $type,
  221. 'meal_id' => $meal_id,
  222. 'price' => $price,
  223. 'num' => $num,
  224. 'pay_type' => $pay_type
  225. ];
  226. return $this->accessToken->httpRequest(self::MEAL_CODE, $param);
  227. }
  228. }