isWeixin(); if (empty($is_wx)) { echo '请使用微信打开'; } //回调地址 $redirect_uri = request()->input('redirect_url', ''); if (empty($redirect_uri)) { $redirect_uri = 'http://testofficial.jhcs888.com/api/user/cs'; } else { $redirect_uri = base64_decode($redirect_uri); } if (empty($redirect_uri)) { echo '请携带回调地址'; }else{ //上级推广码 $invite_code = request()->input('inviteCode', ''); //微信静默授权 $wx_info = WeixinServer::creatServer()->authorize(); if ($wx_info) { //微信登录 $ret = UserServer::creatServer()->setWxOpen($wx_info,$invite_code); if (empty($ret)) { //获取微信信息失败 echo '登陆失败'; } else { $ret = http_build_query($ret); if (strpos($redirect_uri, '?') !== false) { $redirect_uri .= ('&' . $ret); } else { $redirect_uri .= ('?' . $ret); } //跳转至原来的页面 WeixinServer::creatServer()->redirect($redirect_uri); } } else { echo '获取基本信息失败'; } } } /** * 获取视频信息 * @return \Illuminate\Http\JsonResponse */ function getVideo(){ $m_id = request()->input('m_id', '');//浏览者 $token = request()->input('token', '');//token if(empty($m_id) || empty($token)) return $this->apiResponseError('',[],401); $check = $this->checkLogin($m_id,$token); if(!$check) return $this->apiResponseError('',[],401); $data['one_video'] = Config::where('key','one_video')->value('value'); $data['two_video'] = Config::where('key','two_video')->value('value'); $data['three_video'] = Config::where('key','three_video')->value('value'); $data['four_video'] = Config::where('key','four_video')->value('value'); return $this->apiResponseSuccess('成功',$data); } /** * 记录浏览数据 * @return \Illuminate\Http\JsonResponse */ function setRecord(){ $s_code = request()->input('s_code', '');//上级推广码 $m_id = request()->input('m_id', '');//浏览者 $token = request()->input('token', '');//token if(empty($m_id) || empty($token)) return $this->apiResponseError('',[],401); $check = $this->checkLogin($m_id,$token); if(!$check) return $this->apiResponseError('',[],401); if(empty($s_code) || empty($m_id)) return $this->apiResponseSuccess('完成'); //检查上级是否存在 $s_user = WxUser::where('invite_code', $s_code)->select(['id'])->first(); if($s_user){ $s_user->increment('pv');//记录pv量 }else{ return $this->apiResponseSuccess('完成'); } //检查浏览者是否存在 $user = WxUser::where('id', $m_id)->select(['id'])->first(); if($user){ //检查这个浏览者是否浏览过这个上级的 $info = WxRecord::where('s_code',$s_code)->where('m_id',$m_id)->select(['id'])->first(); if(empty($info)){ $s_user->increment('uv');//记录uv量 WxRecord::create([ 's_code' => $s_code, 'm_id' => $m_id, ]); } } return $this->apiResponseSuccess('完成'); } /** * 发送短信 * @return \Illuminate\Http\JsonResponse * @throws \End01here\EasySms\Exceptions\CodeErrorException * @throws \End01here\EasySms\Exceptions\GatewayErrorException * @throws \End01here\EasySms\Exceptions\MessageException */ function sendSms() { $phone = request()->input('phone', ''); $send_type = request()->input('send_type', 'default'); if (empty($phone)) { return $this->apiResponseError('请输入手机号码'); } $send_server = SmsServer::creatServer(); $ret = $send_server->sendCode($phone, $send_type); if (!$ret) { return $this->apiResponseError($send_server->getErrorMsg() ?: '短信发送失败'); } else { return $this->apiResponseSuccess('短信发送成功'); } } /** * 申请成为推广者 * @return \Illuminate\Http\JsonResponse */ function setApply(){ $m_id = request()->input('m_id', ''); $name = request()->input('name', '');//名称 $phone = request()->input('phone', '');//账号 $code = request()->input('code', '');//验证码 $token = request()->input('token', '');//token if(empty($m_id) || empty($token)) return $this->apiResponseError('',[],401); $check = $this->checkLogin($m_id,$token); if(!$check) return $this->apiResponseError('',[],401); if (empty($m_id)) return $this->apiResponseError( '必要参数缺失'); if (empty($name)) return $this->apiResponseError( '名称必填'); if (mb_strlen($name) > 10) return $this->apiResponseError('名称10字以内'); if (empty($phone)) return $this->apiResponseError( '手机号必填'); if (!CommonServer::creatServer()->verifyPhoneNumber($phone)) { return $this->apiResponseError('手机号格式错误'); } if (empty($code)) return $this->apiResponseError( '验证码必填'); $send_server = SmsServer::creatServer(); $code_ret = $send_server->verifyCode($phone, $code); if (empty($code_ret)) { return $this->apiResponseError($send_server->getErrorMsg() ?: '验证码错误'); } $info = WxUser::where('phone', $phone)->select(['id'])->first(); if ($info) { return $this->apiResponseError( '该号码已申请'); } $res = WxUser::where('id',$m_id)->update(['name'=>$name, 'phone'=>$phone, 'status'=>1]); if($res){ $data['status'] = 1; return $this->apiResponseSuccess( '申请成功',$data); }else{ return $this->apiResponseError( '申请失败'); } } /** * 报名信息 * @return \Illuminate\Http\JsonResponse|void */ function setSignUp(){ $m_id = request()->input('m_id', ''); $name = request()->input('name', '');//名称 $phone = request()->input('phone', '');//账号 $industry = request()->input('industry', '');//行业 $address = request()->input('address', '');//地址 $token = request()->input('token', '');//token if(empty($m_id) || empty($token)) return $this->apiResponseError('',[],401); $check = $this->checkLogin($m_id,$token); if(!$check) return $this->apiResponseError('',[],401); if (empty($m_id)) return $this->apiResponseError( '必要参数缺失'); if (empty($name)) return $this->apiResponseError( '名称必填'); if (mb_strlen($name) > 10) return $this->apiResponseError('名称10字以内'); if (empty($industry)) return $this->apiResponseError('行业必填'); if (mb_strlen($industry) > 100) return $this->apiResponseError('行业信息过长'); if (empty($address)) return $this->apiResponseError('地址必填'); if (empty($phone)) return $this->apiResponseError( '手机号必填'); if (!CommonServer::creatServer()->verifyPhoneNumber($phone)) { return $this->apiResponseError('手机号格式错误'); } $info = WxSignup::where('phone', $phone)->select(['id'])->first(); if ($info) { return $this->apiResponseError( '该号码已提交'); } //获取用户上级 $p_id = WxUser::where('id',$m_id)->value('p_id'); $res = WxSignup::create([ 'p_id' => $p_id, 'm_id' => $m_id, 'name' => $name, 'phone' => $phone, 'industry' => $industry, 'address' => $address, ]); if($res){ return $this->apiResponseSuccess( '提交成功'); }else{ return $this->apiResponseError( '提交失败'); } } /** * 获取JS签名信息 * @return \Illuminate\Http\JsonResponse */ function getJsConfig() { $url = request()->input('url'); $ret = WeixinServer::creatServer()->getJsConfig($url); return $this->apiResponseSuccess('获取信息成功', $ret); } /** * 检查会员登陆 * @param $m_id * @param $token * @return bool */ function checkLogin($m_id,$token){ $member = WxUser::where('id',$m_id)->select(['id','token_str'])->first(); if(empty($member)){ return false; } if ($member['token_str'] != $token) { return false; } return true; } }