Commit 8c772fce authored by muhong's avatar muhong

修改 支付宝获取user_id

parent 39991996
......@@ -9,7 +9,7 @@ import java.util.Date;
/**
* @author shiyu
* @date 2023/08/07
* @date 2023/09/28
*/
@Data
public class User implements Serializable {
......@@ -98,6 +98,11 @@ public class User implements Serializable {
*/
private String weixinOpenid;
/**
* 支付宝user_id
*/
private String alipayUserId;
/**
* 微信号
*/
......@@ -147,6 +152,7 @@ public class User implements Serializable {
sb.append(", profile=").append(profile);
sb.append(", background=").append(background);
sb.append(", weixinOpenid=").append(weixinOpenid);
sb.append(", alipayUserId=").append(alipayUserId);
sb.append(", wechatId=").append(wechatId);
sb.append(", status=").append(status);
sb.append(", addTime=").append(addTime);
......@@ -184,6 +190,7 @@ public class User implements Serializable {
&& (this.getProfile() == null ? other.getProfile() == null : this.getProfile().equals(other.getProfile()))
&& (this.getBackground() == null ? other.getBackground() == null : this.getBackground().equals(other.getBackground()))
&& (this.getWeixinOpenid() == null ? other.getWeixinOpenid() == null : this.getWeixinOpenid().equals(other.getWeixinOpenid()))
&& (this.getAlipayUserId() == null ? other.getAlipayUserId() == null : this.getAlipayUserId().equals(other.getAlipayUserId()))
&& (this.getWechatId() == null ? other.getWechatId() == null : this.getWechatId().equals(other.getWechatId()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
......@@ -210,6 +217,7 @@ public class User implements Serializable {
result = prime * result + ((getProfile() == null) ? 0 : getProfile().hashCode());
result = prime * result + ((getBackground() == null) ? 0 : getBackground().hashCode());
result = prime * result + ((getWeixinOpenid() == null) ? 0 : getWeixinOpenid().hashCode());
result = prime * result + ((getAlipayUserId() == null) ? 0 : getAlipayUserId().hashCode());
result = prime * result + ((getWechatId() == null) ? 0 : getWechatId().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
......@@ -252,6 +260,7 @@ public class User implements Serializable {
profile("profile", "profile", "VARCHAR", false),
background("background", "background", "VARCHAR", false),
weixinOpenid("weixin_openid", "weixinOpenid", "VARCHAR", false),
alipayUserId("alipay_user_id", "alipayUserId", "VARCHAR", false),
wechatId("wechat_id", "wechatId", "VARCHAR", false),
status("status", "status", "TINYINT", true),
addTime("add_time", "addTime", "TIMESTAMP", false),
......
......@@ -2113,6 +2113,148 @@ public class UserExample {
return (Criteria) this;
}
public Criteria andAlipayUserIdIsNull() {
addCriterion("alipay_user_id is null");
return (Criteria) this;
}
public Criteria andAlipayUserIdIsNotNull() {
addCriterion("alipay_user_id is not null");
return (Criteria) this;
}
public Criteria andAlipayUserIdEqualTo(String value) {
addCriterion("alipay_user_id =", value, "alipayUserId");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andAlipayUserIdEqualToColumn(User.Column column) {
addCriterion(new StringBuilder("alipay_user_id = ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andAlipayUserIdNotEqualTo(String value) {
addCriterion("alipay_user_id <>", value, "alipayUserId");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andAlipayUserIdNotEqualToColumn(User.Column column) {
addCriterion(new StringBuilder("alipay_user_id <> ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andAlipayUserIdGreaterThan(String value) {
addCriterion("alipay_user_id >", value, "alipayUserId");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andAlipayUserIdGreaterThanColumn(User.Column column) {
addCriterion(new StringBuilder("alipay_user_id > ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andAlipayUserIdGreaterThanOrEqualTo(String value) {
addCriterion("alipay_user_id >=", value, "alipayUserId");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andAlipayUserIdGreaterThanOrEqualToColumn(User.Column column) {
addCriterion(new StringBuilder("alipay_user_id >= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andAlipayUserIdLessThan(String value) {
addCriterion("alipay_user_id <", value, "alipayUserId");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andAlipayUserIdLessThanColumn(User.Column column) {
addCriterion(new StringBuilder("alipay_user_id < ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andAlipayUserIdLessThanOrEqualTo(String value) {
addCriterion("alipay_user_id <=", value, "alipayUserId");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andAlipayUserIdLessThanOrEqualToColumn(User.Column column) {
addCriterion(new StringBuilder("alipay_user_id <= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andAlipayUserIdLike(String value) {
addCriterion("alipay_user_id like", value, "alipayUserId");
return (Criteria) this;
}
public Criteria andAlipayUserIdNotLike(String value) {
addCriterion("alipay_user_id not like", value, "alipayUserId");
return (Criteria) this;
}
public Criteria andAlipayUserIdIn(List<String> values) {
addCriterion("alipay_user_id in", values, "alipayUserId");
return (Criteria) this;
}
public Criteria andAlipayUserIdNotIn(List<String> values) {
addCriterion("alipay_user_id not in", values, "alipayUserId");
return (Criteria) this;
}
public Criteria andAlipayUserIdBetween(String value1, String value2) {
addCriterion("alipay_user_id between", value1, value2, "alipayUserId");
return (Criteria) this;
}
public Criteria andAlipayUserIdNotBetween(String value1, String value2) {
addCriterion("alipay_user_id not between", value1, value2, "alipayUserId");
return (Criteria) this;
}
public Criteria andWechatIdIsNull() {
addCriterion("wechat_id is null");
return (Criteria) this;
......
......@@ -16,6 +16,7 @@
<result column="profile" jdbcType="VARCHAR" property="profile" />
<result column="background" jdbcType="VARCHAR" property="background" />
<result column="weixin_openid" jdbcType="VARCHAR" property="weixinOpenid" />
<result column="alipay_user_id" jdbcType="VARCHAR" property="alipayUserId" />
<result column="wechat_id" jdbcType="VARCHAR" property="wechatId" />
<result column="status" jdbcType="TINYINT" property="status" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
......@@ -83,8 +84,8 @@
</sql>
<sql id="Base_Column_List">
id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level,
nickname, mobile, avatar, profile, background, weixin_openid, wechat_id, `status`,
add_time, update_time, deleted, share_user_id
nickname, mobile, avatar, profile, background, weixin_openid, alipay_user_id, wechat_id,
`status`, add_time, update_time, deleted, share_user_id
</sql>
<select id="selectByExample" parameterType="com.wwdz.ch.db.domain.UserExample" resultMap="BaseResultMap">
select
......@@ -120,8 +121,8 @@
</when>
<otherwise>
id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level,
nickname, mobile, avatar, profile, background, weixin_openid, wechat_id, `status`,
add_time, update_time, deleted, share_user_id
nickname, mobile, avatar, profile, background, weixin_openid, alipay_user_id, wechat_id,
`status`, add_time, update_time, deleted, share_user_id
</otherwise>
</choose>
from user
......@@ -173,8 +174,8 @@
</when>
<otherwise>
id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level,
nickname, mobile, avatar, profile, background, weixin_openid, wechat_id, `status`,
add_time, update_time, deleted, share_user_id
nickname, mobile, avatar, profile, background, weixin_openid, alipay_user_id, wechat_id,
`status`, add_time, update_time, deleted, share_user_id
</otherwise>
</choose>
from user
......@@ -198,16 +199,16 @@
birthday, last_login_time, last_login_ip,
user_level, nickname, mobile,
avatar, profile, background,
weixin_openid, wechat_id, `status`,
add_time, update_time, deleted,
share_user_id)
weixin_openid, alipay_user_id, wechat_id,
`status`, add_time, update_time,
deleted, share_user_id)
values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{gender,jdbcType=TINYINT},
#{birthday,jdbcType=DATE}, #{lastLoginTime,jdbcType=TIMESTAMP}, #{lastLoginIp,jdbcType=VARCHAR},
#{userLevel,jdbcType=TINYINT}, #{nickname,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR},
#{avatar,jdbcType=VARCHAR}, #{profile,jdbcType=VARCHAR}, #{background,jdbcType=VARCHAR},
#{weixinOpenid,jdbcType=VARCHAR}, #{wechatId,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT},
#{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT},
#{shareUserId,jdbcType=BIGINT})
#{weixinOpenid,jdbcType=VARCHAR}, #{alipayUserId,jdbcType=VARCHAR}, #{wechatId,jdbcType=VARCHAR},
#{status,jdbcType=TINYINT}, #{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{deleted,jdbcType=BIT}, #{shareUserId,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.User">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
......@@ -254,6 +255,9 @@
<if test="weixinOpenid != null">
weixin_openid,
</if>
<if test="alipayUserId != null">
alipay_user_id,
</if>
<if test="wechatId != null">
wechat_id,
</if>
......@@ -313,6 +317,9 @@
<if test="weixinOpenid != null">
#{weixinOpenid,jdbcType=VARCHAR},
</if>
<if test="alipayUserId != null">
#{alipayUserId,jdbcType=VARCHAR},
</if>
<if test="wechatId != null">
#{wechatId,jdbcType=VARCHAR},
</if>
......@@ -384,6 +391,9 @@
<if test="record.weixinOpenid != null">
weixin_openid = #{record.weixinOpenid,jdbcType=VARCHAR},
</if>
<if test="record.alipayUserId != null">
alipay_user_id = #{record.alipayUserId,jdbcType=VARCHAR},
</if>
<if test="record.wechatId != null">
wechat_id = #{record.wechatId,jdbcType=VARCHAR},
</if>
......@@ -423,6 +433,7 @@
profile = #{record.profile,jdbcType=VARCHAR},
background = #{record.background,jdbcType=VARCHAR},
weixin_openid = #{record.weixinOpenid,jdbcType=VARCHAR},
alipay_user_id = #{record.alipayUserId,jdbcType=VARCHAR},
wechat_id = #{record.wechatId,jdbcType=VARCHAR},
`status` = #{record.status,jdbcType=TINYINT},
add_time = #{record.addTime,jdbcType=TIMESTAMP},
......@@ -475,6 +486,9 @@
<if test="weixinOpenid != null">
weixin_openid = #{weixinOpenid,jdbcType=VARCHAR},
</if>
<if test="alipayUserId != null">
alipay_user_id = #{alipayUserId,jdbcType=VARCHAR},
</if>
<if test="wechatId != null">
wechat_id = #{wechatId,jdbcType=VARCHAR},
</if>
......@@ -511,6 +525,7 @@
profile = #{profile,jdbcType=VARCHAR},
background = #{background,jdbcType=VARCHAR},
weixin_openid = #{weixinOpenid,jdbcType=VARCHAR},
alipay_user_id = #{alipayUserId,jdbcType=VARCHAR},
wechat_id = #{wechatId,jdbcType=VARCHAR},
`status` = #{status,jdbcType=TINYINT},
add_time = #{addTime,jdbcType=TIMESTAMP},
......@@ -553,8 +568,8 @@
</when>
<otherwise>
id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level,
nickname, mobile, avatar, profile, background, weixin_openid, wechat_id, `status`,
add_time, update_time, deleted, share_user_id
nickname, mobile, avatar, profile, background, weixin_openid, alipay_user_id, wechat_id,
`status`, add_time, update_time, deleted, share_user_id
</otherwise>
</choose>
from user
......
......@@ -25,4 +25,5 @@ public class UserRequestDto implements Entity {
// 快捷登录方式(1、微信,2、支付宝,3、抖音)
private Integer loginType;
private String wxOpenId;
private String alipayUserId;
}
......@@ -179,6 +179,7 @@ public class UserServiceImpl implements UserService {
if (StringUtils.equals("false", mobile)) {
return Result.failed("用户信息解密失败");
}
dto.setAlipayUserId(alipayLoginManager.getAlipayUserId(dto.getLoginCode()));
}
if (dto.getLoginType().equals(LoginTypeEnum.TIKTOK.getCode())) {
String sessionKey = tikTokLoginManager.getSessionKey(dto.getLoginCode());
......@@ -456,9 +457,8 @@ public class UserServiceImpl implements UserService {
user.setWechatId("");
user.setMobile(dto.getMobile());
user.setAvatar(avatarUrl);
if (StringUtils.isNotBlank(dto.getWxOpenId())) {
user.setWeixinOpenid(dto.getWxOpenId());
}
user.setWeixinOpenid(dto.getWxOpenId());
user.setAlipayUserId(dto.getAlipayUserId());
while (true) {
String nickname = "收藏家" + StringUtil.generateRandomString(10);
if (!userDao.isExistedByNickname(0L, nickname)) {
......@@ -480,6 +480,9 @@ public class UserServiceImpl implements UserService {
if (StringUtils.isNotBlank(dto.getWxOpenId())) {
user.setWeixinOpenid(dto.getWxOpenId());
}
if (StringUtils.isNotBlank(dto.getAlipayUserId())) {
user.setAlipayUserId(dto.getAlipayUserId());
}
user.setLastLoginTime(new Date());
user.setLastLoginIp(IpUtil.client(request));
if (userDao.updateById(user) == 0) {
......
......@@ -5,11 +5,14 @@ import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipayEncrypt;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayOpenAppQrcodeCreateRequest;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.response.AlipayOpenAppQrcodeCreateResponse;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.xxdxxs.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -90,6 +93,36 @@ public class AlipayLoginManager {
return JsonUtils.getValueByPath(plainData, "mobile");
}
public String getAlipayUserId(String loginCode) {
logger.info("开始解密获取支付宝小程序登录用户的access_token");
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
alipayConfig.setAppId(appid);
alipayConfig.setPrivateKey(privateKey);
alipayConfig.setFormat("json");
alipayConfig.setAlipayPublicKey(signVeriKey);
alipayConfig.setCharset("UTF8");
alipayConfig.setSignType("RSA2");
try {
AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
request.setCode(loginCode);
request.setGrantType("authorization_code");
AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
logger.info("调用支付宝小程序获取登录用户的access_token的结果:" + response.getBody());
if (response.isSuccess()) {
logger.info("调用支付宝小程序获取登录用户的access_token成功");
return JsonUtils.getValueByPath(response.getBody(), "alipay_system_oauth_token_response/user_id");
} else {
logger.info("调用支付宝小程序获取登录用户的access_token失败");
return "";
}
} catch (Exception e) {
logger.error("调用支付宝小程序获取登录用户的access_token异常");
return "";
}
}
/**
* 获取二维码
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment