CrmebPlatService.php 5.9 KB

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