提交代码
parent
06d152aaeb
commit
265a7abb1a
|
@ -0,0 +1,10 @@
|
||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 公众号绑定
|
||||||
|
export function wxBinding(data) {
|
||||||
|
return request({
|
||||||
|
url: '/wxAuth/binding',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
|
@ -1,15 +1,19 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="app-content">
|
<div class="app-content">
|
||||||
<el-row>
|
<el-row style="margin-top: 40%" v-if="errorVisible || successVisible">
|
||||||
<el-col :sm="24" :lg="24">
|
<el-col :sm="24" :lg="24" v-if="successVisible">
|
||||||
<el-result icon="success" title="消息授权成功">
|
<el-result icon="success" title="公众号消息授权成功">
|
||||||
<template slot="extra">
|
<template slot="extra">
|
||||||
<el-button type="primary" size="medium" round>返回小程序</el-button>
|
<el-button type="primary" size="medium" round>返回小程序</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-result>
|
</el-result>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :sm="24" :lg="24">
|
<el-col :sm="24" :lg="24" v-if="errorVisible">
|
||||||
<el-result icon="error" title="消息授权失败" subTitle="请关注公众号并进行网页授权">
|
<el-result
|
||||||
|
icon="error"
|
||||||
|
title="公众号消息授权失败"
|
||||||
|
subTitle="请关注公众号并进行网页授权"
|
||||||
|
>
|
||||||
<template slot="extra">
|
<template slot="extra">
|
||||||
<el-button type="primary" size="medium" round>返回小程序</el-button>
|
<el-button type="primary" size="medium" round>返回小程序</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
@ -20,19 +24,21 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { wxBinding } from "@/api/wxsetting/wxAuth";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "build",
|
name: "build",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
uId: null,
|
uId: null,
|
||||||
uIdErrorShow: false,
|
errorVisible: false,
|
||||||
successVisible: false,
|
successVisible: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {},
|
|
||||||
created() {
|
created() {
|
||||||
this.uId = this.getQueryString("userOpenId") || "";
|
this.uId = this.getQueryString("userOpenId") || "";
|
||||||
if (this.uId == "") {
|
if (this.uId == "") {
|
||||||
|
this.errorVisible = true;
|
||||||
} else {
|
} else {
|
||||||
this.wechatLogin();
|
this.wechatLogin();
|
||||||
}
|
}
|
||||||
|
@ -40,11 +46,13 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
wechatLogin() {
|
wechatLogin() {
|
||||||
// 处理微信授权登录
|
// 处理微信授权登录
|
||||||
|
let rd = this.getQueryString("rd") || "";
|
||||||
let openId = this.getQueryString("openId") || "";
|
let openId = this.getQueryString("openId") || "";
|
||||||
// token === '' && openId != '' 只要这种情况,未绑定账号
|
// token === '' && openId != '' 只要这种情况,未绑定账号
|
||||||
if (openId != "") {
|
if (openId != "" && rd != "") {
|
||||||
// 绑定账号
|
// 绑定账号
|
||||||
console.log("dialogVisible===>", openId, this.uId);
|
console.log("接口返回===>", openId, this.uId, rd);
|
||||||
|
this.saveBinding(uId, openId);
|
||||||
} else {
|
} else {
|
||||||
// 如果绑定了,返回成功
|
// 如果绑定了,返回成功
|
||||||
console.log("我要去登录了===>");
|
console.log("我要去登录了===>");
|
||||||
|
@ -57,8 +65,34 @@ export default {
|
||||||
this.uId;
|
this.uId;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveBind() {
|
saveBinding(uId, openId) {
|
||||||
console.log("saveBind");
|
/**
|
||||||
|
* uId 小程序openId
|
||||||
|
* openId 公众号openId
|
||||||
|
*/
|
||||||
|
wxBinding({ openId: uId, msgOpenId: openId }).then((response) => {
|
||||||
|
if (response.code == 200) {
|
||||||
|
this.successVisible = true;
|
||||||
|
} else {
|
||||||
|
this.errorVisible = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
colse() {
|
||||||
|
if (typeof WeixinJSBridge == "undefined") {
|
||||||
|
if (document.addEventListener) {
|
||||||
|
document.addEventListener("WeixinJSBridgeReady", weixin_ClosePage, false);
|
||||||
|
} else if (document.attachEvent) {
|
||||||
|
document.attachEvent("WeixinJSBridgeReady", weixin_ClosePage);
|
||||||
|
document.attachEvent("onWeixinJSBridgeReady", weixin_ClosePage);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
WeixinJSBridge.call("closeWindow");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
weixin_ClosePage() {
|
||||||
|
//关闭微信浏览器
|
||||||
|
WeixinJSBridge.call("closeWindow");
|
||||||
},
|
},
|
||||||
getQueryString(paramName) {
|
getQueryString(paramName) {
|
||||||
if (window.location.href.indexOf("?") == -1) return "";
|
if (window.location.href.indexOf("?") == -1) return "";
|
||||||
|
@ -85,4 +119,17 @@ export default {
|
||||||
url("https://szgcwx.jhncidg.com/staticFiles/img/CORE_40247DD946964A15AA0D4000E1031E19.png")
|
url("https://szgcwx.jhncidg.com/staticFiles/img/CORE_40247DD946964A15AA0D4000E1031E19.png")
|
||||||
no-repeat bottom/100%;
|
no-repeat bottom/100%;
|
||||||
}
|
}
|
||||||
|
.el-result__title p {
|
||||||
|
color: #ffffff !important;
|
||||||
|
}
|
||||||
|
.el-result__subtitle p {
|
||||||
|
color: red !important;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
.el-result__extra {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.el-result__extra button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -95,6 +95,7 @@ public class WechatUserLoginServiceImpl implements IWechatUserLoginService {
|
||||||
userInfo.put("roleId",userData.get("roleId"));
|
userInfo.put("roleId",userData.get("roleId"));
|
||||||
userInfo.put("roleName",userData.get("roleName"));
|
userInfo.put("roleName",userData.get("roleName"));
|
||||||
userInfo.put("minRoleId",userData.get("minRoleId"));
|
userInfo.put("minRoleId",userData.get("minRoleId"));
|
||||||
|
userInfo.put("openId",openId);
|
||||||
/** 查询当前用户项目信息 **/
|
/** 查询当前用户项目信息 **/
|
||||||
|
|
||||||
SurProject surProject = new SurProject();
|
SurProject surProject = new SurProject();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.ruoyi.common.core.redis.RedisCache;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.system.domain.SysUserOpenid;
|
import com.ruoyi.system.domain.SysUserOpenid;
|
||||||
import com.ruoyi.system.service.ISysUserOpenidService;
|
import com.ruoyi.system.service.ISysUserOpenidService;
|
||||||
|
import com.yanzhu.jh.wxsetting.domain.vo.WxBindingVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.chanjar.weixin.common.api.WxConsts;
|
import me.chanjar.weixin.common.api.WxConsts;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
|
@ -17,6 +18,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -126,7 +128,7 @@ public class WxAuthController extends BaseController {
|
||||||
|
|
||||||
//注意拼接参数,第一个参数需要加问号,之后参数使用&拼接的问题
|
//注意拼接参数,第一个参数需要加问号,之后参数使用&拼接的问题
|
||||||
//return "redirect:" + returnUrl + "/#/?openid=" + openId;
|
//return "redirect:" + returnUrl + "/#/?openid=" + openId;
|
||||||
response.sendRedirect(returnUrl + "&openid=" + openId);
|
response.sendRedirect(returnUrl + "&rd="+System.currentTimeMillis()+"&openid=" + openId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,15 +138,13 @@ public class WxAuthController extends BaseController {
|
||||||
* 获取用户信息类,最后重定向到指定url
|
* 获取用户信息类,最后重定向到指定url
|
||||||
*/
|
*/
|
||||||
@Anonymous
|
@Anonymous
|
||||||
@GetMapping("/binding")
|
@PostMapping("/binding")
|
||||||
public AjaxResult binding(String openId,String msgOpenId) throws Exception {
|
public AjaxResult binding(@Validated @RequestBody WxBindingVo vo) throws Exception {
|
||||||
/*当用户同意授权后,将小程序openId和公众号OpenId进行绑定*/
|
/*当用户同意授权后,将小程序openId和公众号OpenId进行绑定*/
|
||||||
if(StringUtils.isNotBlank(openId)){
|
SysUserOpenid sysUserOpenid = sysUserOpenidService.selectSysUserOpenidByOpenId(vo.getOpenId());
|
||||||
SysUserOpenid sysUserOpenid = sysUserOpenidService.selectSysUserOpenidByOpenId(openId);
|
if(sysUserOpenid!=null){
|
||||||
if(sysUserOpenid!=null){
|
sysUserOpenid.setMsgOpenId(vo.getMsgOpenId());
|
||||||
sysUserOpenid.setMsgOpenId(msgOpenId);
|
return toAjax(sysUserOpenidService.updateSysUserOpenid(sysUserOpenid));
|
||||||
return toAjax(sysUserOpenidService.updateSysUserOpenid(sysUserOpenid));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return error();
|
return error();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.yanzhu.jh.wxsetting.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公众号绑定 请求参数
|
||||||
|
*
|
||||||
|
* @author: JiangYuQi
|
||||||
|
* @date: 2024/04/13 12:21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WxBindingVo {
|
||||||
|
|
||||||
|
/** 小程序openId */
|
||||||
|
@NotBlank(message = "小程序openId不能为空")
|
||||||
|
@Size(max = 128, message = "小程序openId最大128位")
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
/** 公众号openId */
|
||||||
|
@NotBlank(message = "公众号openId不能为空")
|
||||||
|
@Size(max = 128, message = "小程序openId最大128位")
|
||||||
|
private String msgOpenId;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue