|
@@ -0,0 +1,77 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace app\admin\controller;
|
|
|
+
|
|
|
+use think\App;
|
|
|
+use app\admin\BaseController as Base;
|
|
|
+use think\facade\Validate;
|
|
|
+use think\facade\Db;
|
|
|
+class WeChat extends Base {
|
|
|
+ public $wechat;
|
|
|
+ public function __construct(App $App) {
|
|
|
+ parent::__construct($App);
|
|
|
+ $wechat_conf =env("wechat");
|
|
|
+ $this->wechat=new \think\Wechat($wechat_conf);
|
|
|
+ }
|
|
|
+// 获取用户信息
|
|
|
+// "userid": "zhangsan",
|
|
|
+// * "name": "李四",
|
|
|
+// * "department": [1, 2],
|
|
|
+// * "position": "后台工程师",
|
|
|
+// * "mobile": "15913215421",
|
|
|
+// * "gender": 1, //性别。gender=0表示男,=1表示女
|
|
|
+// * "tel": "62394",
|
|
|
+// * "email": "zhangsan@gzdev.com",
|
|
|
+// * "weixinid": "lisifordev", //微信号
|
|
|
+// * "avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3W..../0", //头像url。注:如果要获取小图将url最后的"/0"改成"/64"即可
|
|
|
+// * "status": 1 //关注状态: 1=已关注,2=已冻结,4=未关注
|
|
|
+// * "extattr": {"attrs":[{"name":"爱好","value":"旅游"},{"name":"卡号","value":"1234567234"}]}
|
|
|
+ public function getinfo(){
|
|
|
+ $code =$this->request->only(["code"=>""],"post","trim");
|
|
|
+ $valid =Validate::rule(["code|微信授权Code"=>"require|max:255|min:5"]);
|
|
|
+ if($valid->check($code)==false) return error_show(1004,$valid->getError());
|
|
|
+
|
|
|
+ $uid =$this->wechat->getUserId($code['code']);
|
|
|
+ if($uid==false){
|
|
|
+ return error_show(1004,"未获取到用户数据");
|
|
|
+ }
|
|
|
+ if(!isset($uid['UserId'])|| $uid['UserId']) return error_show(1004,"未获取到用户数据");
|
|
|
+ $Dbuser =Db::name("wechat_user")->where(["userid"=>$uid['UserId']])->findOrEmpty();
|
|
|
+ if(empty($Dbuser)){
|
|
|
+ $useinfo = $this->wechat->getUserInfo($uid['UserId']);
|
|
|
+ if($useinfo==false)return error_show(1004,"未获取到用户数据");
|
|
|
+ $Dbuser = [
|
|
|
+ "userid"=>$useinfo['userid'],
|
|
|
+ "position"=>$useinfo['userid'],
|
|
|
+ "mobile"=>$useinfo['userid'],
|
|
|
+ "gender"=>$useinfo['userid'],
|
|
|
+ "tel"=>$useinfo['userid'],
|
|
|
+ "email"=>$useinfo['userid'],
|
|
|
+ "weixinid"=>$useinfo['userid'],
|
|
|
+ "avatar"=>$useinfo['userid'],
|
|
|
+ "status"=>$useinfo['userid'],
|
|
|
+ "extattr"=>$useinfo['userid'],
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $Dbuser['id']=Db::name("wechat_user")->insertGetId($Dbuser);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ $Dbuser["updatetime"]=date("Y-m-d H:i:s");
|
|
|
+ Db::name("wechat_user")->save($Dbuser);
|
|
|
+ }
|
|
|
+ return app_show(0,"获取成功",$Dbuser);
|
|
|
+ }
|
|
|
+ //网页端调用jssdk配置config
|
|
|
+ public function getConfig(){
|
|
|
+ $url =$this->request->only(["url"=>""],"post","trim");
|
|
|
+ $valid =Validate::rule(["code|微信授权Code"=>"require|max:255|min:5"]);
|
|
|
+ if($valid->check($url)==false) return error_show(1004,$valid->getError());
|
|
|
+ $baseconfig =$this->wechat->getJsSign($url['url']);
|
|
|
+ if($baseconfig==false){
|
|
|
+ return error_show(1004,"为获取到用户数据");
|
|
|
+ }
|
|
|
+ return app_show(0,"获取成功",$baseconfig);
|
|
|
+ }
|
|
|
+}
|