提交代码
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>
|
||||
<div class="app-content">
|
||||
<el-row>
|
||||
<el-col :sm="24" :lg="24">
|
||||
<el-result icon="success" title="消息授权成功">
|
||||
<el-row style="margin-top: 40%" v-if="errorVisible || successVisible">
|
||||
<el-col :sm="24" :lg="24" v-if="successVisible">
|
||||
<el-result icon="success" title="公众号消息授权成功">
|
||||
<template slot="extra">
|
||||
<el-button type="primary" size="medium" round>返回小程序</el-button>
|
||||
</template>
|
||||
</el-result>
|
||||
</el-col>
|
||||
<el-col :sm="24" :lg="24">
|
||||
<el-result icon="error" title="消息授权失败" subTitle="请关注公众号并进行网页授权">
|
||||
<el-col :sm="24" :lg="24" v-if="errorVisible">
|
||||
<el-result
|
||||
icon="error"
|
||||
title="公众号消息授权失败"
|
||||
subTitle="请关注公众号并进行网页授权"
|
||||
>
|
||||
<template slot="extra">
|
||||
<el-button type="primary" size="medium" round>返回小程序</el-button>
|
||||
</template>
|
||||
|
@ -20,19 +24,21 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { wxBinding } from "@/api/wxsetting/wxAuth";
|
||||
|
||||
export default {
|
||||
name: "build",
|
||||
data() {
|
||||
return {
|
||||
uId: null,
|
||||
uIdErrorShow: false,
|
||||
errorVisible: false,
|
||||
successVisible: false,
|
||||
};
|
||||
},
|
||||
watch: {},
|
||||
created() {
|
||||
this.uId = this.getQueryString("userOpenId") || "";
|
||||
if (this.uId == "") {
|
||||
this.errorVisible = true;
|
||||
} else {
|
||||
this.wechatLogin();
|
||||
}
|
||||
|
@ -40,11 +46,13 @@ export default {
|
|||
methods: {
|
||||
wechatLogin() {
|
||||
// 处理微信授权登录
|
||||
let rd = this.getQueryString("rd") || "";
|
||||
let openId = this.getQueryString("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 {
|
||||
// 如果绑定了,返回成功
|
||||
console.log("我要去登录了===>");
|
||||
|
@ -57,8 +65,34 @@ export default {
|
|||
this.uId;
|
||||
}
|
||||
},
|
||||
saveBind() {
|
||||
console.log("saveBind");
|
||||
saveBinding(uId, openId) {
|
||||
/**
|
||||
* 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) {
|
||||
if (window.location.href.indexOf("?") == -1) return "";
|
||||
|
@ -85,4 +119,17 @@ export default {
|
|||
url("https://szgcwx.jhncidg.com/staticFiles/img/CORE_40247DD946964A15AA0D4000E1031E19.png")
|
||||
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>
|
||||
|
|
|
@ -95,6 +95,7 @@ public class WechatUserLoginServiceImpl implements IWechatUserLoginService {
|
|||
userInfo.put("roleId",userData.get("roleId"));
|
||||
userInfo.put("roleName",userData.get("roleName"));
|
||||
userInfo.put("minRoleId",userData.get("minRoleId"));
|
||||
userInfo.put("openId",openId);
|
||||
/** 查询当前用户项目信息 **/
|
||||
|
||||
SurProject surProject = new SurProject();
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.ruoyi.common.core.redis.RedisCache;
|
|||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.SysUserOpenid;
|
||||
import com.ruoyi.system.service.ISysUserOpenidService;
|
||||
import com.yanzhu.jh.wxsetting.domain.vo.WxBindingVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -126,7 +128,7 @@ public class WxAuthController extends BaseController {
|
|||
|
||||
//注意拼接参数,第一个参数需要加问号,之后参数使用&拼接的问题
|
||||
//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
|
||||
*/
|
||||
@Anonymous
|
||||
@GetMapping("/binding")
|
||||
public AjaxResult binding(String openId,String msgOpenId) throws Exception {
|
||||
@PostMapping("/binding")
|
||||
public AjaxResult binding(@Validated @RequestBody WxBindingVo vo) throws Exception {
|
||||
/*当用户同意授权后,将小程序openId和公众号OpenId进行绑定*/
|
||||
if(StringUtils.isNotBlank(openId)){
|
||||
SysUserOpenid sysUserOpenid = sysUserOpenidService.selectSysUserOpenidByOpenId(openId);
|
||||
if(sysUserOpenid!=null){
|
||||
sysUserOpenid.setMsgOpenId(msgOpenId);
|
||||
return toAjax(sysUserOpenidService.updateSysUserOpenid(sysUserOpenid));
|
||||
}
|
||||
SysUserOpenid sysUserOpenid = sysUserOpenidService.selectSysUserOpenidByOpenId(vo.getOpenId());
|
||||
if(sysUserOpenid!=null){
|
||||
sysUserOpenid.setMsgOpenId(vo.getMsgOpenId());
|
||||
return toAjax(sysUserOpenidService.updateSysUserOpenid(sysUserOpenid));
|
||||
}
|
||||
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