USVT-126 针对微信的 API 调用,在拿到 Code 后我们需要在本地存储 Access Token,我顺便调用了用户的信息 API 获得用户的头像和昵称

This commit is contained in:
YuCheng Hu 2022-12-06 07:49:25 -05:00
parent 7a2a1ea908
commit 5012d38027
2 changed files with 15 additions and 21 deletions

View File

@ -6,14 +6,12 @@ import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.LocalDateTime;
/**
* Created with IntelliJ IDEA.
* WeChat API Call State to get user information and access token
*
* @Author: XieYang
* @Date: 2022/10/10/19:21
* @Description:
* @author YuCheng
*/
@Entity
@Data
@ -21,30 +19,24 @@ import java.time.LocalDateTime;
@org.hibernate.annotations.Table(appliesTo = "wechat_call_state", comment = "WeChat Call State")
public class WeChatCallState extends BaseEntity<Long> {
/**
* User id
*/
@Column(name = "wechat_state", columnDefinition = "varchar(255) COMMENT 'wechat state'")
private String weChatState;
/**
* User olc password
*/
@Column(name = "wechat_code", columnDefinition = "varchar(255) COMMENT 'wechat code")
private String weChatCode;
@Column(name = "wechat_access_token", columnDefinition = "varchar(255) COMMENT 'wechat access token")
private String weChatAccessToken;
@Column(name = "wechat_openid", columnDefinition = "varchar(255) COMMENT 'wechat openid'")
private String weChatOpenId;
/**
* User new password
*/
@Column(name = "wechat_unionid", columnDefinition = "varchar(255) COMMENT 'wechat unionid'")
private String weChatUnionId;
/**
* User change password time
*/
@Column(name = "date_call_state", columnDefinition = "DATETIME COMMENT 'User change password time'")
private LocalDateTime dateCallState;
@Column(name = "nickname", columnDefinition = "varchar(255) COMMENT 'wechat nickname'")
private String nickName;
@Column(name = "head_img_url", columnDefinition = "varchar(255) COMMENT 'wechat head image url'")
private String headImgURL;
}

View File

@ -73,6 +73,8 @@ public class WeChatService {
log.debug("WeChat NickName - [{}]", weChatUser.getNickname());
WeChatCallState weChatCallState = new WeChatCallState();
weChatCallState.setWeChatState(weChatState);
weChatCallState.setWeChatCode(weChatCode);
weChatCallState.setWeChatAccessToken(accessToken);
weChatCallState.setWeChatOpenId(weChatUser.getOpenId());
weChatCallState.setWeChatUnionId(weChatUser.getUnionId());
weChatCallStateRepository.save(weChatCallState);