提交 3dc73409 作者: zhenjie

微信调用、用户相关接口

上级 2df3064a
......@@ -22,6 +22,7 @@ public enum ResultEnum implements BaseErrorInfoInterface{
PASSWORD_INCONSISTENT("5026", "新密码与确认密码不一致,请确认一致"),
WX_ACCESS_TOKEN_ERROR("5027", "获取微信AccessToken失败"),
APPLET_QR_CODE_CREATE_ERROR("5030", "生成小程序码错误:"),
AUTH_PHONE_NUMBER_ERROR("5031", "授权手机号失败"),
PWD_CREATE_ERROR("6001", "创建密码失败"),
PWD_CONPARED_ERROR("6002", "密码错误"), PWD_ALERT_ERROR("6003", "密码不一致"),
......
......@@ -5,10 +5,7 @@ import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.dto.UserAccountSimpleDTO;
import com.mmc.iuav.user.model.vo.UserAccountVO;
import com.mmc.iuav.user.service.UserAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -56,4 +53,12 @@ public class UserAccountController extends BaseController{
return userAccountService.feignListUserAccountIds(provinceCode, cityCode, districtCode);
}
@ApiOperation(value = "授权手机号")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = Integer.class) })
@GetMapping("getUserPhoneNumber")
public ResultBody getUserPhoneNumber(HttpServletRequest request,
@ApiParam(value = "授权手机号code", required = true) @RequestParam String code) {
return userAccountService.getUserPhoneNumber(this.getUserLoginInfo(request).getId(), code);
}
}
......@@ -18,7 +18,7 @@ import java.io.PrintWriter;
@Api(tags = "微信相关接口")
@RequestMapping("/wx/")
@RestController
public class WxController {
public class WxController extends BaseController {
@Autowired
private WxService wxService;
......@@ -26,15 +26,15 @@ public class WxController {
@ApiOperation(value = "小程序-获取当前用户的小程序推荐码")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = String.class) })
@PostMapping("getAppletRcdCode")
public ResultBody getAppletRcdCode(HttpServletRequest request) {
return null;
public ResultBody getAppletRcdCode(HttpServletRequest request, @ApiParam(value = "小程序路径",example = "pages/welcome/index") @RequestParam String page) {
return wxService.getUnLimitedQRCode(page, "currentUserAccountId=" + this.getUserLoginInfo(request).getId());
}
@ApiOperation(value = "小程序-测试专用")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = ResultBody.class) })
@PostMapping("testDemo")
public ResultBody testDemo() {
return ResultBody.success("app:" + wxService.getAccessToken() + "sub: " + wxService.getSubAccessToken());
return ResultBody.success("app:" + "wxService.getAccessToken()" + "sub: " + wxService.getSubAccessToken());
}
/**
......@@ -54,7 +54,7 @@ public class WxController {
return ResultBody.success(wxService.createUrlLink(path, query));
}
@ApiOperation(value = "监控微信公众号的事件变化通知")
@ApiOperation(value = "监控微信公众号的事件变化通知", hidden = true)
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = String.class) })
@PostMapping("wxSendMessage")
public void wxSendMessage(HttpServletRequest req, HttpServletResponse resp) throws IOException {
......@@ -65,4 +65,11 @@ public class WxController {
String msg = wxService.receiveSubAccountEvents(req);
out.println(msg);
}
@ApiOperation(value = "生成小程序码")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = ResultBody.class) })
@GetMapping("getAppletQRCode")
public ResultBody getAppletQRCode(@ApiParam(value = "小程序路径",example = "pages/welcome/index") @RequestParam String page,@ApiParam(value = "参数",example = "name=123&sex=456") @RequestParam String scene) {
return wxService.getUnLimitedQRCode(page, scene);
}
}
......@@ -44,6 +44,9 @@ public class UserAccountDO implements Serializable {
private Integer cityCode;
private Integer districtCode;
private Integer cooperationTagId;
private Integer companyAuthStatus;
public UserAccountDO(UserAccountVO userAccountVO) {
this.id = userAccountVO.getId();
this.phoneNum = userAccountVO.getPhoneNum();
......@@ -73,12 +76,13 @@ public class UserAccountDO implements Serializable {
public UserAccountVO buildUserAccountVO() {
return UserAccountVO.builder().id(this.id).uid(this.uid).accountNo(this.accountNo).accountType(this.accountType).phoneNum(this.phoneNum).userName(this.userName).nickName(this.nickName)
.userImg(this.userImg).userSex(this.userSex).email(this.email).source(this.source).accountStatus(this.accountStatus).remark(this.remark).portType(this.portType)
.createTime(this.createTime).build();
.createTime(this.createTime).companyAuthStatus(this.companyAuthStatus).cooperationTagId(this.cooperationTagId).build();
}
public UserAccountSimpleDTO buildUserAccountSimpleDTO() {
return UserAccountSimpleDTO.builder().id(this.id).uid(this.uid).accountNo(this.accountNo).accountType(this.accountType).phoneNum(this.phoneNum).userName(this.userName).nickName(this.nickName)
.userImg(this.userImg).userSex(this.userSex).email(this.email).source(this.source).accountStatus(this.accountStatus).portType(this.portType)
.companyAuthStatus(this.companyAuthStatus == null || this.companyAuthStatus != 1 ? 0 : 1).cooperationTagId(this.cooperationTagId)
.build();
}
}
......@@ -115,4 +115,12 @@ public interface UserAccountService {
* @return
*/
ResultBody feignAuthUserPwd(Integer id, String authPwd);
/**
* 授权手机号
* @param id
* @param code
* @return
*/
ResultBody getUserPhoneNumber(Integer id, String code);
}
......@@ -6,7 +6,6 @@ import com.mmc.iuav.user.model.vo.WxLoginVO;
import com.mmc.iuav.user.model.vo.WxMsgVO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author: zj
......@@ -64,5 +63,20 @@ public interface WxService {
*/
ResultBody sendAppletMsg(AppletMsgVO appletMsgVO);
/**
* 生成小程序链接
* @param path
* @param query
* @return
*/
String createUrlLink(String path, String query);
/**
* 获取用户授权手机号
*
* @param id
* @param code
* @return
*/
String getUserPhoneNumber(Integer id, String code);
}
package com.mmc.iuav.user.service.impl;
import com.mmc.iuav.auth.JwtConstant;
import com.mmc.iuav.general.CodeUtil;
import com.mmc.iuav.page.PageResult;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.response.ResultEnum;
import com.mmc.iuav.user.auth.PwdUtil;
import com.mmc.iuav.user.constant.UserSystemConstant;
import com.mmc.iuav.user.dao.CooperationDao;
import com.mmc.iuav.user.dao.UserServiceDao;
import com.mmc.iuav.user.entity.UserAccountDO;
......@@ -18,9 +16,10 @@ import com.mmc.iuav.user.model.vo.CompanyAuthVO;
import com.mmc.iuav.user.model.vo.UserAccountVO;
import com.mmc.iuav.user.service.CompanyAuthService;
import com.mmc.iuav.user.service.UserAccountService;
import com.mmc.iuav.user.service.WxService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.security.NoSuchAlgorithmException;
import java.util.List;
......@@ -42,6 +41,9 @@ public class UserAccountServiceImpl implements UserAccountService {
@Autowired
private CooperationDao cooperationDao;
@Autowired
private WxService wxService;
@Override
public UserAccountVO getUserAccountInfoByUnionId(String unionId) {
UserAccountDO userAccountDO = userServiceDao.getUserAccountInfoByUnionId(unionId);
......@@ -162,6 +164,9 @@ public class UserAccountServiceImpl implements UserAccountService {
@Override
public List<UserAccountSimpleDTO> feignListBAccountPage(BUserAccountQO bUserAccountQO) {
List<UserAccountDO> list = userServiceDao.feignListBAccountPage(bUserAccountQO);
if (list == null) {
return null;
}
List<UserAccountSimpleDTO> accountSimpleDTOS = list.stream().map(UserAccountDO::buildUserAccountSimpleDTO).collect(Collectors.toList());
return accountSimpleDTOS;
}
......@@ -214,4 +219,18 @@ public class UserAccountServiceImpl implements UserAccountService {
}
return ResultBody.success();
}
@Override
public ResultBody getUserPhoneNumber(Integer id, String code) {
String userPhoneNumber = wxService.getUserPhoneNumber(id, code);
if (StringUtils.isBlank(userPhoneNumber)){
return ResultBody.error(ResultEnum.AUTH_PHONE_NUMBER_ERROR);
}
System.out.println("userPhoneNumber:"+userPhoneNumber);
UserAccountDO userAccount = new UserAccountDO();
userAccount.setId(id);
userAccount.setPhoneNum(userPhoneNumber);
userServiceDao.update(userAccount);
return ResultBody.success();
}
}
......@@ -64,11 +64,11 @@ public class WxServiceImpl implements WxService {
String accessToken = stringRedisTemplate.opsForValue().get(WxConstant.IUAV_MINI_PROGRAM_ACCESS_TOKEN);
if (StringUtils.isBlank(accessToken)){
String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token" + "?grant_type=client_credential" + "&appid=" +
userSystemConstant.getWxAppId() + "&secret" + userSystemConstant.getWxAppSecret();
userSystemConstant.getWxAppId() + "&secret=" + userSystemConstant.getWxAppSecret();
String accessTokenMsg = HttpsRequestUtil.httpsGet(getAccessTokenUrl, null);
JSONObject tokenResult = JSONObject.parseObject(accessTokenMsg);
if (accessTokenMsg.indexOf("access_token") == -1) {
System.out.println("获取用户信息有误:access_token请求失败:" + tokenResult);
System.out.println("获取小程序access_token有误:" + tokenResult);
return null;
}
accessToken = tokenResult.getString("access_token");
......@@ -86,11 +86,11 @@ public class WxServiceImpl implements WxService {
String accessToken = stringRedisTemplate.opsForValue().get(WxConstant.SHARE_FLY_SUB_ACCESS_TOKEN);
if (StringUtils.isBlank(accessToken)){
String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token" + "?grant_type=client_credential" + "&appid=" +
userSystemConstant.getWxSubAppId() + "&secret" + userSystemConstant.getWxSubSecret();
userSystemConstant.getWxSubAppId() + "&secret=" + userSystemConstant.getWxSubSecret();
String accessTokenMsg = HttpsRequestUtil.httpsGet(getAccessTokenUrl, null);
JSONObject tokenResult = JSONObject.parseObject(accessTokenMsg);
if (accessTokenMsg.indexOf("access_token") == -1) {
System.out.println("获取用户信息有误:access_token请求失败:" + tokenResult);
System.out.println("获取公众号access_token有误:" + tokenResult);
return null;
}
accessToken = tokenResult.getString("access_token");
......@@ -218,9 +218,11 @@ public class WxServiceImpl implements WxService {
param.put("scene", scene);
param.put("page", path);
param.put("width", 430);
param.put("check_path", false);
param.put("env_version", userSystemConstant.getEnvVersion());
String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
base64 = HttpHelper.httpPost(url, param.toJSONString());
//base64 = HttpHelper.httpPost(url, param.toJSONString());
base64 = HttpsRequestUtil.getACodeBase64(url, "POST", null, param.toJSONString());
return ResultBody.success(base64);
} catch (Exception e) {
return ResultBody.error(ResultEnum.APPLET_QR_CODE_CREATE_ERROR);
......@@ -268,4 +270,25 @@ public class WxServiceImpl implements WxService {
}
return null;
}
@Override
public String getUserPhoneNumber(Integer id, String code) {
try {
String accessToken = this.getAccessToken();
JSONObject param = new JSONObject();
param.put("code", code);
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + accessToken;
String res = HttpHelper.httpPost(url, param.toString());
JSONObject result = JSONObject.parseObject(res);
System.out.println("用户授权手机号:" + res);
if (result.getString("errcode").equals("0")) {
String phone_info = result.getString("phone_info");
JSONObject phoneInfoObject = JSONObject.parseObject(phone_info);
return phoneInfoObject.getString("purePhoneNumber");
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
server:
port: 35150
servlet:
context-path: /userapp
#spring
spring:
application:
name: userapp
#Database
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
......@@ -42,22 +36,12 @@ spring:
# enabled: true
# login-username: druid
# login-password: druid
jackson:
date-format: yyyy-MM-dd HH:mm:ss
redis:
database: 1
host: r-wz9ke310fs684hacn1pd.redis.rds.aliyuncs.com
password: MMC@2022&REDIS
port: 6379
#mybatis
mybatis:
executor-type: simple
mapper-locations: classpath:mapper/**/*.xml
type-aliases-package: com.mmc.iuav.user.entity
configuration:
map-underscore-to-camel-case: true
wx:
sub:
appid: wx5c6a105a0ddca4c5
......
server:
port: 35150
servlet:
context-path: /userapp
#spring
spring:
application:
name: userapp
#Database
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
......@@ -19,16 +13,6 @@ spring:
host: r-wz9ke310fs684hacn1pd.redis.rds.aliyuncs.com
password: MMC@2022&REDIS
port: 6379
jackson:
date-format: yyyy-MM-dd HH:mm:ss
#mybatis
mybatis:
executor-type: simple
mapper-locations: classpath:mapper/**/*.xml
type-aliases-package: com.mmc.iuav.user
configuration:
map-underscore-to-camel-case: true
wx:
sub:
......
server:
port: 35150
servlet:
context-path: /userapp
#spring
spring:
application:
name: userapp
#Database
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
......@@ -42,22 +36,12 @@ spring:
# enabled: true
# login-username: druid
# login-password: druid
jackson:
date-format: yyyy-MM-dd HH:mm:ss
redis:
database: 1
host: r-wz9ke310fs684hacn1pd.redis.rds.aliyuncs.com
password: MMC@2022&REDIS
port: 6379
#mybatis
mybatis:
executor-type: simple
mapper-locations: classpath:mapper/**/*.xml
type-aliases-package: com.mmc.iuav.user
configuration:
map-underscore-to-camel-case: true
wx:
sub:
appid: wx5c6a105a0ddca4c5
......
server:
port: 35150
servlet:
context-path: /userapp
spring:
profiles:
active: local
application:
name: userapp
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
#mybatis
mybatis:
executor-type: simple
mapper-locations: classpath:mapper/**/*.xml
type-aliases-package: com.mmc.iuav.user
configuration:
map-underscore-to-camel-case: true
---
spring:
......
......@@ -130,23 +130,23 @@
</select>
<select id="feignListBAccountPage" resultType="com.mmc.iuav.user.entity.UserAccountDO" parameterType="com.mmc.iuav.user.model.qo.BUserAccountQO">
select id, account_type, account_no, uid, phone_num, user_name, nick_name, user_img, open_id, union_id, user_sex, email, source, account_status, remark,
port_type, is_deleted as deleted, create_time, update_time
from user_account
where is_deleted = 0 and port_type = 0
select ua.id, ua.account_type, ua.account_no, ua.uid, ua.phone_num, ua.user_name, ua.nick_name, ua.user_img, ua.open_id, ua.union_id, ua.user_sex, ua.email, ua.source, ua.account_status, ua.remark,
ua.port_type, ua.is_deleted as deleted, ua.create_time, ua.update_time, ut.cooperation_tag_id, ca.auth_status as companyAuthStatus
from user_account ua left join user_tag ut on ua.id = ut.user_account_id left join company_auth ca on ua.id = ca.user_account_id
where ua.is_deleted = 0
<if test=" userIds != null ">
<foreach collection="userIds" item="id" open="and id in (" close=")" separator=",">
<foreach collection="userIds" item="id" open="and ua.id in (" close=")" separator=",">
#{id}
</foreach>
</if>
<if test="provinceCode != null">
and province_code = #{provinceCode}
and ua.province_code = #{provinceCode}
</if>
<if test="cityCode != null">
and city_code = #{cityCode}
and ua.city_code = #{cityCode}
</if>
<if test="districtCode != null">
and district_code = #{districtCode}
and ua.district_code = #{districtCode}
</if>
</select>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论