Compare commits

..

No commits in common. "f8833cd1fd3601bbd051e538f0ad296ab21804e5" and "61cac97d84caa2076145220e11ae81aea89a6c03" have entirely different histories.

5 changed files with 20 additions and 105 deletions

View File

@ -1,10 +0,0 @@
import request from '@/utils/request'
// 公众号绑定
export function wxBinding(data) {
return request({
url: '/wxAuth/binding',
method: 'post',
data: data
})
}

View File

@ -1,19 +1,15 @@
<template>
<div class="app-content">
<el-row style="margin-top: 40%" v-if="errorVisible || successVisible">
<el-col :sm="24" :lg="24" v-if="successVisible">
<el-result icon="success" title="公众号消息授权成功">
<el-row>
<el-col :sm="24" :lg="24">
<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" v-if="errorVisible">
<el-result
icon="error"
title="公众号消息授权失败"
subTitle="请关注公众号并进行网页授权"
>
<el-col :sm="24" :lg="24">
<el-result icon="error" title="消息授权失败" subTitle="请关注公众号并进行网页授权">
<template slot="extra">
<el-button type="primary" size="medium" round>返回小程序</el-button>
</template>
@ -24,21 +20,19 @@
</template>
<script>
import { wxBinding } from "@/api/wxsetting/wxAuth";
export default {
name: "build",
data() {
return {
uId: null,
errorVisible: false,
uIdErrorShow: false,
successVisible: false,
};
},
watch: {},
created() {
this.uId = this.getQueryString("userOpenId") || "";
if (this.uId == "") {
this.errorVisible = true;
} else {
this.wechatLogin();
}
@ -46,13 +40,11 @@ export default {
methods: {
wechatLogin() {
//
let rd = this.getQueryString("rd") || "";
let openId = this.getQueryString("openId") || "";
// token === '' && openId != ''
if (openId != "" && rd != "") {
if (openId != "") {
//
console.log("接口返回===>", openId, this.uId, rd);
this.saveBinding(uId, openId);
console.log("dialogVisible===>", openId, this.uId);
} else {
//
console.log("我要去登录了===>");
@ -65,34 +57,8 @@ export default {
this.uId;
}
},
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");
saveBind() {
console.log("saveBind");
},
getQueryString(paramName) {
if (window.location.href.indexOf("?") == -1) return "";
@ -119,17 +85,4 @@ 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>

View File

@ -95,7 +95,6 @@ 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();

View File

@ -9,7 +9,6 @@ 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;
@ -18,7 +17,6 @@ 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;
@ -128,7 +126,7 @@ public class WxAuthController extends BaseController {
//注意拼接参数,第一个参数需要加问号,之后参数使用&拼接的问题
//return "redirect:" + returnUrl + "/#/?openid=" + openId;
response.sendRedirect(returnUrl + "&rd="+System.currentTimeMillis()+"&openid=" + openId);
response.sendRedirect(returnUrl + "&openid=" + openId);
}
/**
@ -138,14 +136,16 @@ public class WxAuthController extends BaseController {
* url
*/
@Anonymous
@PostMapping("/binding")
public AjaxResult binding(@Validated @RequestBody WxBindingVo vo) throws Exception {
@GetMapping("/binding")
public AjaxResult binding(String openId,String msgOpenId) throws Exception {
/*当用户同意授权后将小程序openId和公众号OpenId进行绑定*/
SysUserOpenid sysUserOpenid = sysUserOpenidService.selectSysUserOpenidByOpenId(vo.getOpenId());
if(StringUtils.isNotBlank(openId)){
SysUserOpenid sysUserOpenid = sysUserOpenidService.selectSysUserOpenidByOpenId(openId);
if(sysUserOpenid!=null){
sysUserOpenid.setMsgOpenId(vo.getMsgOpenId());
sysUserOpenid.setMsgOpenId(msgOpenId);
return toAjax(sysUserOpenidService.updateSysUserOpenid(sysUserOpenid));
}
}
return error();
}

View File

@ -1,27 +0,0 @@
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;
}