集成支付宝登录

This commit is contained in:
jinqiming 2021-06-06 15:48:28 +08:00
parent dbe6994d09
commit b079b99279
7 changed files with 73 additions and 20 deletions

View File

@ -1,5 +1,6 @@
package com.snow.web.controller.dingtalk;
import com.snow.common.constant.Constants;
import com.snow.common.core.controller.BaseController;
import com.snow.common.core.domain.AjaxResult;
import com.snow.common.utils.ServletUtils;
@ -15,6 +16,7 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.AuthAlipayRequest;
import me.zhyd.oauth.request.AuthDingTalkRequest;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthWeChatEnterpriseRequest;
@ -54,19 +56,24 @@ public class ThirdOauthController extends BaseController {
* @param source
* @throws IOException
*/
@GetMapping("/toDingPage/{source}")
@GetMapping("/toPage/{source}")
@ResponseBody
public void renderAuth(@PathVariable("source") String source) throws IOException
{
AuthRequest authRequest =null;
switch (source){
case "dingtalk":
authRequest= getDingTalkAuthRequest();
break;
case "weChart":
authRequest=getWeChatAuthRequest();
break;
}
case "dingtalk":
authRequest= getDingTalkAuthRequest();
break;
case "weChart":
authRequest=getWeChatAuthRequest();
break;
case "alipay":
authRequest = getAlipayAuthRequest();
break;
}
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
ServletUtils.getResponse().sendRedirect(authorizeUrl);
@ -97,6 +104,18 @@ public class ThirdOauthController extends BaseController {
}
/**
* 支付宝登录
* @param callback
* @param request
* @return
*/
@SuppressWarnings("unchecked")
@GetMapping("/alipayLogin")
public Object alipayLogin(AuthCallback callback, HttpServletRequest request)
{
return thirdLogin("alipay",getAlipayAuthRequest(),callback);
}
/**
* 检查是否授权
@ -144,11 +163,26 @@ public class ThirdOauthController extends BaseController {
* @return
*/
private AuthRequest getWeChatAuthRequest() {
String clientId= iSysConfigService.selectConfigByKey("wechart.login.clientId");
String appSecret= iSysConfigService.selectConfigByKey("wechart.login.appSecret");
String redirectUri= iSysConfigService.selectConfigByKey("wechart.login.redirectUri");
String agentId= iSysConfigService.selectConfigByKey("wechart.login.agentId");
return new AuthWeChatEnterpriseRequest(AuthConfig.builder()
.clientId("ww2354bcd694497bd8")
.clientSecret("EzODWvC9zdPJJS4KnCNVENB3UhSiYCbmr9UrFpOM9dQ")
.redirectUri("http://workflow.vaiwan.com/third/oauth/weChartLogin")
.agentId("1000002")
.clientId(clientId)
.clientSecret(appSecret)
.redirectUri(redirectUri)
.agentId(agentId)
.build());
}
private AuthRequest getAlipayAuthRequest() {
String appId= iSysConfigService.selectConfigByKey("alipay.login.appId");
String redirectUri= iSysConfigService.selectConfigByKey("alipay.login.redirectUri");
return new AuthAlipayRequest(AuthConfig.builder()
.clientId(appId)
.clientSecret(Constants.ALIPAY_RSA_PRIVATE_KEY)
.alipayPublicKey(Constants.ALIPAY_PUBLIC_KEY)
.redirectUri(redirectUri)
.build());
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

View File

@ -67,18 +67,18 @@
</div>
<div class="ui horizontal list login-oauth__list">
<div class="item" title="使用 钉钉 账号授权登录">
<a th:href="@{/third/oauth/toDingPage/dingtalk}">
<a th:href="@{/third/oauth/toPage/dingtalk}">
<img src="../static/img/dingtalk.png" th:src="@{/img/dingtalk.png}"/>
</a>
</div>
<div class="item" title="使用 企业微信 账号授权登录">
<a th:href="@{/third/oauth/toDingPage/weChart}">
<a th:href="@{/third/oauth/toPage/weChart}">
<img src="../static/img/weixin.svg" th:src="@{/img/weixin.svg}"/>
</a>
</div>
<div class="item" title="功能开发中...">
<a href="#">
<img src="../static/img/qq.svg" th:src="@{/img/qq.svg}"/>
<div class="item" title="使用 支付宝 账号授权登录">
<a th:href="@{/third/oauth/toPage/alipay}">
<img src="../static/img/qq.svg" th:src="@{/img/alipay.png}"/>
</a>
</div>
</div>

View File

@ -155,9 +155,9 @@
<div class="git-other-login-icon"><img th:src="@{/img/weixin.svg}"></div>
<span class="app-name">WeiXin</span></a>
<a class="third-app" href="#" title="功能开发中...">
<a class="third-app" href="javascript:void(0)" th:onclick="authUrl('alipay');" title="使用 支付宝 账号授权登录">
<div class="git-other-login-icon"><img th:src="@{/img/qq.svg}"></div>
<span class="app-name">QQ</span></a>
<span class="app-name">AliPay</span></a>
</div>
</div>
</div>
@ -399,7 +399,7 @@
data: { "source": source },
success: function(r) {
if (r.code == web_status.SUCCESS) {
var url = "/third/oauth/toDingPage/" + source;
var url = "/third/oauth/toPage/" + source;
top.location.href =url;
} else {
$.modal.msgError(r.msg);

View File

@ -163,6 +163,11 @@
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>3.7.4.ALL</version>
</dependency>
</dependencies>
</project>

View File

@ -168,4 +168,18 @@ public class Constants
*/
public static final String Ding_Flow="DingFlow";
/**
* 支付宝公钥
*/
public static final String ALIPAY_PUBLIC_KEY="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq1t0PeHM9KjQksI/qQTGXc5z3ic9a7sq6uThianOEB8xUZMT2Qe505L3XGWiyk7UNpnyEqOmvgrkG7SkbF/LJlmnowrL8Akkju72famdJ/imTsPRdHyEFFo5hmqUTsaeR56SKMcLINlCX+bIunva9c8uN1N6C1DmSYywOUx1Wj7wpVWWFHs1KsM13Nbe45VL4v76XXUvXOXSEYNlfu8/MvK8rjPHliqwDp2CRUG/oj14SJmZI1myGgqYHVMHmoBQI1wJg66ow5XdLKYy252edMKwOSnOBfcR/uNFw0292Cv4TKFDmyn3ox/MptHW2UqLSqVC80eJpIVPGjlYpyC5PwIDAQAB";
/***
* 公钥
*/
public static final String ALIPAY_RSA_PUBLIC_KEY="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApbNsg+nw0thcPCvrmBNPrpfGSQHh5gtlZTuo7/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