diff --git a/application/plugins/view/weixinwebauthorization/index/public/success.html b/application/plugins/view/weixinwebauthorization/index/public/success.html new file mode 100644 index 000000000..e462f9b55 --- /dev/null +++ b/application/plugins/view/weixinwebauthorization/index/public/success.html @@ -0,0 +1,55 @@ +{{include file="public/header" /}} + + +{{if isset($is_header) and $is_header eq 1}} + + {{include file="public/header_top_nav" /}} + + + {{include file="public/nav_search" /}} + + + {{include file="public/goods_category" /}} +{{/if}} + + + +
';
- print_r($ret);
+ // 获取用户信息
+ $ret = $this->UserInfo($ret['data']);
+ if($ret['code'] != 0)
+ {
+ $this->assign('msg', $ret['msg']);
+ return $this->fetch('public/tips_error');
+ }
+
+ // 处理用户数据
+ $ret = Service::WeixinAuthReg($ret['data']);
+ if($ret['code'] == 0)
+ {
+ $this->assign('msg', $ret['msg']);
+ $this->assign('data', $ret['data']);
+ return $this->fetch('../../../plugins/view/weixinwebauthorization/index/public/success');
+ } else {
+ $this->assign('msg', $ret['msg']);
+ return $this->fetch('public/error');
+ }
}
/**
- * 获取access_token
+ * 获取用户信息
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-24
* @desc description
- * @param array $params [description]
+ * @param [array] $params [输入参数]
*/
- private function AccessToken($params = [])
+ private function UserInfo($params = [])
{
-
-
+ // 参数校验
+ if(empty($params['access_token']))
+ {
+ return DataReturn('access_token为空', -1);
+ }
+ if(empty($params['openid']))
+ {
+ return DataReturn('openid为空', -1);
+ }
+
+ // 获取用户详细信息
+ $url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$params['access_token'].'&openid='.$params['openid'].'&lang=zh_CN';
+ $data = json_decode(file_get_contents($url), true);
+ if(empty($data['openid']))
+ {
+ if(empty($data['errmsg']))
+ {
+ return DataReturn('获取用户信息失败', -100);
+ } else {
+ return DataReturn($data['errmsg'], -100);
+ }
+ }
+ return DataReturn('获取成功', 0, $data);
}
/**
@@ -105,7 +147,7 @@ class Auth extends Controller
* @version 1.0.0
* @date 2019-05-24
* @desc description
- * @param array $params [description]
+ * @param [array] $params [输入参数]
*/
private function RemoteAccessToken($params = [])
{
@@ -129,9 +171,16 @@ class Auth extends Controller
// 获取access_token
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$ret['data']['appid'].'&secret='.$ret['data']['secret'].'&code='.$params['code'].'&grant_type=authorization_code';
$data = json_decode(file_get_contents($url), true);
-
- echo '';
- print_r($data);die;
+ if(empty($data['access_token']))
+ {
+ if(empty($data['errmsg']))
+ {
+ return DataReturn('获取access_token失败', -100);
+ } else {
+ return DataReturn($data['errmsg'], -100);
+ }
+ }
+ return DataReturn('获取成功', 0, $data);
} else {
return DataReturn($ret['msg'], -1);
diff --git a/application/plugins/weixinwebauthorization/install.sql b/application/plugins/weixinwebauthorization/install.sql
new file mode 100644
index 000000000..d6e7d3d7d
--- /dev/null
+++ b/application/plugins/weixinwebauthorization/install.sql
@@ -0,0 +1,2 @@
+# 用户
+ALTER TABLE `s_user` add `weixin_web_openid` char(60) NOT NULL DEFAULT '' COMMENT '微信web用户openid' after `weixin_openid`;
\ No newline at end of file
diff --git a/application/plugins/weixinwebauthorization/service/Service.php b/application/plugins/weixinwebauthorization/service/Service.php
new file mode 100755
index 000000000..8b4458c86
--- /dev/null
+++ b/application/plugins/weixinwebauthorization/service/Service.php
@@ -0,0 +1,91 @@
+$user['username'], 'pwd'=>$user['username']]);
+ if($ret['code'] == 0)
+ {
+ return DataReturn('登录成功', 0, $ret['data']);
+ }
+ }
+ } else {
+ return DataReturn('用户openid为空', -1);
+ }
+
+ // 游客数据
+ $salt = GetNumberCode(6);
+ $data = [
+ 'weixin_web_openid' => $params['openid'],
+ 'username' => $params['openid'],
+ 'nickname' => empty($params['nickname']) ? '' : $params['nickname'],
+ 'gender' => empty($params['sex']) ? 0 : (isset($params['sex']) && $params['sex'] == 1) ? 2 : 1,
+ 'province' => empty($params['province']) ? '' : $params['province'],
+ 'city' => empty($params['city']) ? '' : $params['city'],
+ 'avatar' => empty($params['headimgurl']) ? '' : $params['headimgurl'],
+ 'status' => 0,
+ 'salt' => $salt,
+ 'pwd' => LoginPwdEncryption($params['openid'], $salt),
+ 'add_time' => time(),
+ 'upd_time' => time(),
+ ];
+
+ // 数据添加
+ $ret = UserService::UserInsert($data, $params);
+ if($ret['code'] == 0)
+ {
+ // 用户登录session纪录
+ if(UserService::UserLoginRecord($ret['data']['user_id']))
+ {
+ return DataReturn('登录成功', 0, $ret['data']);
+ }
+ }
+ return DataReturn('登录失败', -100);
+ }
+}
+?>
\ No newline at end of file