User.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\ListCallTaskResponseBody\data;
  4. use app\common\controller\Api;
  5. use app\common\library\Ems;
  6. use app\common\library\Sms;
  7. use fast\Random;
  8. use think\Config;
  9. use think\Validate;
  10. use think\Db;
  11. use wxpay;
  12. /**
  13. * 会员接口
  14. */
  15. class User extends Api
  16. {
  17. protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'registercheck', 'resetpwd', 'changeemail', 'changemobile', 'third', 'getopenid', 'getagreement', 'wxlogin', 'mobileloginregister'];
  18. protected $noNeedRight = '*';
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. if (!Config::get('fastadmin.usercenter')) {
  23. $this->error(__('User center already closed'));
  24. }
  25. }
  26. //////////////////////////////////////////////////////
  27. //手机号登录/注册
  28. public function mobileloginregister() {
  29. $user_token = input('user_token', '', 'trim');
  30. if (!$user_token) {
  31. $this->error('参数缺失');
  32. }
  33. $url = 'http://' . config('pingtai_ip') . ':8081/bussiness/1.0/hdc/svc/sso/loginUserInfo/cmtokenid/' . $user_token;
  34. //获取鉴权token
  35. $sign_bytes = '/1.0/hdc/svc/sso/loginUserInfo/cmtokenid/' . $user_token;
  36. $hdc_token = base64_encode(hash_hmac('sha256', $sign_bytes, config('pingtai_appkey'), true));
  37. $header = [
  38. 'Host:' . config('pingtai_ip') . ':8081',
  39. 'Content-Type:application/json',
  40. 'Authorization: HDCAUTH appid="' . config('pingtai_appid') . '",token="' . $hdc_token . '"'
  41. ];
  42. $user_info = httpRequest($url, 'GET', '', $header);
  43. file_put_contents('chen.txt', $user_info, FILE_APPEND);
  44. $user_info = simplexml_load_string($user_info, 'SimpleXMLElement', LIBXML_NOCDATA);
  45. $user_info = (array)$user_info;
  46. if (!$user_info) {
  47. $this->error('您的网络开小差了~');
  48. }
  49. $mobile = isset($user_info['phoneNum']) ? $user_info['phoneNum'] : '';
  50. if (!$mobile) {
  51. $mobile = $this->request->post('mobile');
  52. }
  53. if (!$mobile) {
  54. $this->error(__('Invalid parameters'));
  55. }
  56. /*$mobile = $this->request->post('mobile');
  57. if (!$mobile) {
  58. $this->error(__('Invalid parameters'));
  59. }
  60. if (!Validate::regex($mobile, "^1\d{10}$")) {
  61. $this->error(__('Mobile is incorrect'));
  62. }*/
  63. $user = \app\common\model\User::getByMobile($mobile);
  64. if ($user) {
  65. if ($user->status != 1) {
  66. $this->error(__('Account is locked'));
  67. }
  68. //如果已经有账号则直接登录
  69. $ret = $this->auth->direct($user->id);
  70. } else {
  71. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
  72. }
  73. if ($ret) {
  74. // $data = ['userinfo' => $this->auth->getUserinfo()];
  75. $data = $this->auth->getUserinfo();
  76. $data['hw_ip'] = explode(',', config('site.hw_ip')); //华为播放视频ip
  77. $data['zx_ip'] = explode(',', config('site.zx_ip')); //中兴播放视频ip
  78. $data['display'] = '';//不要删 备用字段
  79. $this->success(__('Logged in successful'), $data);
  80. } else {
  81. $this->error($this->auth->getError());
  82. }
  83. }
  84. //查询我的信息
  85. public function getmyinfo()
  86. {
  87. $user = Db::name('user')->find($this->auth->id);
  88. $data['nickname'] = $user['nickname']; //姓名
  89. $data['username'] = $user['username']; //UID
  90. $data['avatar'] = cdnurl($user['avatar']); //头像
  91. $data['mobile'] = $user['mobile']; //手机号
  92. $data['money'] = $user['money']; //余额
  93. $data['realname'] = $user['realname']; //真实姓名
  94. $data['gender'] = $user['gender']; //性别:1=男,2=女
  95. $data['birthday'] = date('Y-m-d', $user['birthday']); //生日
  96. $data['is_vip'] = 0; //vip是否到期:0到期 1未到期
  97. $data['is_my_vip'] = 0; //健康E家的vip是否到期:0到期 1未到期
  98. //查询vip是否到期
  99. $url = 'http://' . config('pay_ip') . '/HDC/bizauth/phone/auth';
  100. //产品编码集合
  101. $product_codes = [config('product_code')
  102. ];
  103. $vip_jifei = Db::name('vip_jifei')->where('user_switch',1)->where('deletetime',NULL)->column('productcode');
  104. $product_codes = array_merge($product_codes,$vip_jifei);
  105. $product_codes_count = count($product_codes);
  106. $i_max = ceil($product_codes_count / 6);
  107. for ($i = 0; $i < $i_max; $i++) {
  108. $post_product_codes = array_slice($product_codes, $i * 6, 6);
  109. $post_data = [
  110. 'phoneNumber' => $this->auth->mobile,
  111. 'productCodes' => $post_product_codes,
  112. 'channel' => '01'
  113. ];
  114. $post_data = json_encode($post_data, 320);
  115. //获取鉴权token
  116. $sign_bytes = '/bizauth/phone/auth' . $this->base16_encode(md5($post_data));
  117. // $hdc_token = base64_encode(hash_hmac('sha256', $sign_bytes, config('pay_appkey'), true));
  118. $hdc_token = hash_hmac('sha256', $sign_bytes, base64_decode(config('pay_appkey')), false);
  119. $header = [
  120. 'Host:' . config('pay_ip'),
  121. 'Content-Type:application/json',
  122. 'Authorization: HDCAUTH appid="' . config('pay_appid') . '",token="' . $hdc_token . '"'
  123. ];
  124. $rs = httpRequest($url, 'POST', $post_data, $header);
  125. // file_put_contents('chen.txt', $user_info, FILE_APPEND);
  126. if ($rs) {
  127. $rs = json_decode($rs, true);
  128. if ($rs['code'] == '00') {
  129. foreach ($rs['result'] as &$v) {
  130. if ($v['isOrder'] == true) {
  131. $data['is_vip'] = 1;
  132. if($v['productCode'] == config('product_code')){
  133. $data['is_my_vip'] = 1; //因为自己的产品码在第一个,所以不用担心被break掉
  134. }
  135. break 2;//跳出二重循环
  136. }
  137. }
  138. }
  139. }
  140. }
  141. $update = ['updatetime'=>time()];
  142. if ($this->auth->is_vip != $data['is_vip']) {
  143. $update['is_vip'] = $data['is_vip'];
  144. }
  145. if ($this->auth->is_my_vip != $data['is_my_vip']) {
  146. $update['is_my_vip'] = $data['is_my_vip'];
  147. }
  148. Db::name('user')->where(['id' => $this->auth->id])->update($update);
  149. $this->success('信息', $data);
  150. }
  151. //关于我们/免责协议/用户协议/隐私政策/段位介绍
  152. public function getagreement()
  153. {
  154. $type = input('type', 0, 'intval');
  155. if (!in_array($type, [1, 2, 3, 4, 5, 6, 7, 8, 9])) {
  156. $this->error('参数错误');
  157. }
  158. $info = Db::name('platform_info')->field('title, content')->where(['type' => $type])->find();
  159. $this->success('协议', $info);
  160. }
  161. }