123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- /**
- * @author: zhypy<214681832@qq.com>
- * @day: 2020/10/15
- */
- namespace crmeb\services;
- class CrmebPlatService
- {
- /**
- * 验证码
- */
- const PLAT_CODE = 'user/code';
- /**
- * 平台注册
- */
- const PLAT_OPEN = 'user/register';
- /**
- * 用户信息
- */
- const PLAT_USER_INFO = 'user/info';
- /**
- * 修改密码
- */
- const PLAT_USER_MODIFY = 'user/modify';
- /**
- * 找回秘钥
- */
- const PLAT_USER_FORGET = 'user/forget';
- /**
- * 消费记录
- */
- const PLAT_BILL = 'user/bill';
- /**
- * 用量记录
- */
- const PlAT_RRCORD = 'user/record';
- /**
- * 套餐列表
- */
- const MEAL_LIST = 'meal/list';
- /**
- * 支付二维码
- */
- const MEAL_CODE = 'meal/code';
- /**
- * 账号
- * @var null
- */
- protected $account = NULL;
- /**
- * 秘钥
- * @var null
- */
- protected $sercet = NULL;
- /**
- * access_token
- * @var null
- */
- protected $accessToken = NULL;
- public function __construct($account = '', $sercet = '')
- {
- $this->accessToken = $this->getAccessToken($account, $sercet);
- }
- protected function getAccessToken($account, $sercet)
- {
- $this->account = $account ? $account : sys_config('sms_account');
- $this->sercet = $sercet ? $sercet : sys_config('sms_token');
- return new AccessTokenServeService($this->account, $this->sercet);
- }
- /**
- * 获取验证码
- * @param $phone
- * @return bool|mixed
- */
- public function code($phone)
- {
- $param = [
- 'phone' => $phone
- ];
- return $this->accessToken->httpRequest(self::PLAT_CODE, $param, 'POST', false);
- }
- /**
- * 注册
- * @param $account
- * @param $phone
- * @param $password
- * @param $verify_code
- * @return bool
- */
- public function register($account, $phone, $password, $verify_code)
- {
- $param = [
- 'account' => $account,
- 'phone' => $phone,
- 'password' => md5($password),
- 'verify_code' => $verify_code
- ];
- $result = $this->accessToken->httpRequest(self::PLAT_OPEN, $param, 'POST', false);
- return $result;
- }
- /**
- * 登录
- * @param $account
- * @param $secret
- * @return mixed
- */
- public function login($account, $secret)
- {
- $token = $this->getAccessToken($account, $secret)->getToken();
- return $token;
- }
- /**
- * 退出登录
- * @param $account
- * @param $secret
- * @return mixed
- */
- public function loginOut()
- {
- return $this->accessToken->destroyToken();
- }
- /**
- * 用户详情
- * @return mixed
- */
- public function info()
- {
- $result = $this->accessToken->httpRequest(self::PLAT_USER_INFO);
- return $result;
- }
- /**
- * 修改秘钥
- * @param $account
- * @param $phone
- * @param $password
- * @param $verify_code
- * @return bool
- */
- public function modify($account, $phone, $password, $verify_code)
- {
- $param = [
- 'account' => $account,
- 'phone' => $phone,
- 'password' => md5($password),
- 'verify_code' => $verify_code
- ];
- return $this->accessToken->httpRequest(self::PLAT_USER_MODIFY, $param, 'POST', false);
- }
- /**
- * 找回秘钥
- * @param $phone
- * @param $verify_code
- * @return mixed
- */
- public function forget($phone, $verify_code)
- {
- $param = [
- 'phone' => $phone,
- 'verify_code' => $verify_code
- ];
- $result = $this->accessToken->httpRequest(self::PLAT_USER_FORGET, $param, 'POST', false);
- return $result;
- }
- /**
- * 获取消费记录
- * @param int $page
- * @param int $limit
- * @return mixed
- */
- public function bill($page = 0, $limit = 10)
- {
- $param = [
- 'page' => $page,
- 'limit' => $limit
- ];
- $result = $this->accessToken->httpRequest(self::PLAT_BILL, $param);
- return $result;
- }
- /**
- * 获取用量记录
- * @param string $type
- * @param int $page
- * @param int $limit
- * @return array|mixed
- */
- public function record($type = 'sms', $page = 0, $limit = 10)
- {
- $param = [
- 'type' => $type,
- 'page' => $page,
- 'limit' => $limit
- ];
- $result = $this->accessToken->httpRequest(self::PlAT_RRCORD, $param);
- return $result;
- }
- /**
- * 套餐列表
- * @param string $type
- * @return array|bool|mixed
- */
- public function meal($type = 'sms')
- {
- $param = [
- 'type' => $type
- ];
- return $this->accessToken->httpRequest(self::MEAL_LIST, $param);
- }
- /**
- * 获取支付二维码
- * @param $type
- * @param $meal_id
- * @param $price
- * @param $num
- * @param string $pay_type
- * @return array|mixed
- */
- public function pay($type, $meal_id, $price, $num, $pay_type = 'weixin')
- {
- $param = [
- 'type' => $type,
- 'meal_id' => $meal_id,
- 'price' => $price,
- 'num' => $num,
- 'pay_type' => $pay_type
- ];
- return $this->accessToken->httpRequest(self::MEAL_CODE, $param);
- }
- }
|