USVT-125 添加一个通过接口,在这个接口中能够获得微信访问的 Token,同时能够通过 Token 和 OpenId 获得微信用户信息
This commit is contained in:
parent
3fd361d0a4
commit
92bee3b5e9
18
pom.xml
18
pom.xml
|
@ -89,6 +89,18 @@
|
|||
<version>31.1-jre</version>
|
||||
</dependency>
|
||||
|
||||
<!-- UTILS-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.10.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -194,12 +206,6 @@
|
|||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.northtecom.visatrack.api.base.web.Status;
|
|||
import com.northtecom.visatrack.api.controller.vo.ImportReportRequest;
|
||||
import com.northtecom.visatrack.api.controller.vo.VisaCrawlRequest;
|
||||
import com.northtecom.visatrack.api.data.spec.DateRange;
|
||||
import com.northtecom.visatrack.api.model.api.request.CheckeeSyncRequest;
|
||||
import com.northtecom.visatrack.api.model.request.api.CheckeeSyncRequest;
|
||||
import com.northtecom.visatrack.api.service.impl.CrawlService;
|
||||
import com.northtecom.visatrack.api.service.impl.VisaCaseService;
|
||||
import com.northtecom.visatrack.api.service.impl.VisaReportCheckeeService;
|
||||
|
|
|
@ -2,15 +2,24 @@ package com.northtecom.visatrack.api.controller.auth;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.northtecom.visatrack.api.controller.vo.ForgotPasswordRequest;
|
||||
import com.northtecom.visatrack.api.controller.vo.UserChangePasswordResponse;
|
||||
import com.northtecom.visatrack.api.data.entity.UserChangePassword;
|
||||
import com.northtecom.visatrack.api.model.request.auth.WeChatTokenizeRequest;
|
||||
import com.northtecom.visatrack.api.service.impl.UserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -58,10 +67,35 @@ public class WeChatController {
|
|||
qrconnect.append("state=" + UUID.randomUUID().toString() + "#wechat_redirect");
|
||||
|
||||
|
||||
https:
|
||||
//open.weixin.qq.com/connect/qrconnect?appid=wxbdc5610cc59c1631&redirect_uri=https%3A%2F%2Fpassport.yhd.com%2Fwechat%2Fcallback.do&response_type=code&scope=snsapi_login&state=3d6be0a4035d839573b04816624a415e#wechat_redirect
|
||||
|
||||
return qrconnect.toString();
|
||||
}
|
||||
|
||||
@PostMapping("/tokenize")
|
||||
@ResponseBody
|
||||
@Operation(summary = "用户忘记密码接口", description = "用户忘记密码接口,用户忘记密码以后,通过该接口输入一个邮件地址,系统会给用户发送一封邮件,邮件中包含了重置密码的链接,用户点击以后,可以重置密码")
|
||||
public String getWeChatAccessToken(@RequestBody @Valid WeChatTokenizeRequest weChatTokenizeRequest) throws IOException {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
String weChatAppId = "wx26e01c2be46730f3";
|
||||
String weChatSecret = "1eef340a999bc71b431dda85e9bffd3a";
|
||||
String weChatCode = weChatTokenizeRequest.getWeChatCode();
|
||||
String weChatState = weChatTokenizeRequest.getWeChatState();
|
||||
|
||||
HttpUrl.Builder urlBuilder = HttpUrl.parse("https://api.weixin.qq.com/sns/oauth2/access_token").newBuilder();
|
||||
urlBuilder.addQueryParameter("appid", weChatAppId);
|
||||
urlBuilder.addQueryParameter("secret", weChatSecret);
|
||||
urlBuilder.addQueryParameter("code", weChatCode);
|
||||
urlBuilder.addQueryParameter("grant_type", "authorization_code");
|
||||
|
||||
String url = urlBuilder.build().toString();
|
||||
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
Call call = client.newCall(request);
|
||||
|
||||
Response response = call.execute();
|
||||
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,18 @@ import java.time.LocalDateTime;
|
|||
@org.hibernate.annotations.Table(appliesTo = "user", comment = "Customer user for us visa track")
|
||||
public class User extends BaseEntity<Long> {
|
||||
|
||||
/**
|
||||
* User name
|
||||
*/
|
||||
@Column(name = "wechat_unionid", columnDefinition = "varchar(128) COMMENT 'WeChat unionid'")
|
||||
private String wechatUnionid;
|
||||
|
||||
/**
|
||||
* User name
|
||||
*/
|
||||
@Column(name = "wechat_openid", columnDefinition = "varchar(128) COMMENT 'WeChat Openid'")
|
||||
private String wechatOpenid;
|
||||
|
||||
/**
|
||||
* User name
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.northtecom.visatrack.api.model.api.request;
|
||||
package com.northtecom.visatrack.api.model.request.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
Loading…
Reference in New Issue