forked from jyqq163/keycloak-services-social-weixin
-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
116 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/keycloak/social/weixin/egress/wechat/mp/WechatMpApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.keycloak.social.weixin.egress.wechat.mp; | ||
|
||
import lombok.SneakyThrows; | ||
import org.jboss.logging.Logger; | ||
import org.keycloak.broker.provider.util.SimpleHttp; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.social.weixin.egress.wechat.mp.models.AccessTokenResponse; | ||
import org.keycloak.social.weixin.egress.wechat.mp.models.TicketRequest; | ||
import org.keycloak.social.weixin.egress.wechat.mp.models.TicketResponse; | ||
|
||
|
||
public class WechatMpApi { | ||
private static final Logger logger = Logger.getLogger(WechatMpApi.class); | ||
private final String appSecret; | ||
private final String appId; | ||
protected final KeycloakSession session; | ||
|
||
public WechatMpApi(String appId, String appSecret, KeycloakSession session) { | ||
this.appId = appId; | ||
this.appSecret = appSecret; | ||
this.session = session; | ||
} | ||
|
||
@SneakyThrows | ||
public AccessTokenResponse getAccessToken(String appId, String appSecret) { | ||
logger.info(String.format("getAccessToken by %s%n%s%n", appId, appSecret)); | ||
var res = | ||
SimpleHttp.doGet(String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + | ||
"&appid=%s&secret=%s", appId, appSecret), | ||
session).asJson(AccessTokenResponse.class); | ||
|
||
logger.info(String.format("res is %s%n", res)); | ||
|
||
return res; | ||
} | ||
|
||
@SneakyThrows | ||
public TicketResponse createTmpQrCode(TicketRequest ticketRequest) { | ||
logger.info(String.format("createTmpQrCode by %s%n", ticketRequest)); | ||
|
||
var res = SimpleHttp.doPost("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + this.getAccessToken(appId, appSecret).access_token, | ||
session).json(ticketRequest).asJson(TicketResponse.class); | ||
|
||
logger.info(String.format("res is %s%n", res)); | ||
|
||
return res; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ess/wechat/mp/AccessTokenRequestBody.java → ...hat/mp/models/AccessTokenRequestBody.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/org/keycloak/social/weixin/egress/wechat/mp/models/AccessTokenResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.keycloak.social.weixin.egress.wechat.mp.models; | ||
|
||
public class AccessTokenResponse { | ||
public String access_token; | ||
public String expires_in; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/keycloak/social/weixin/egress/wechat/mp/models/ActionInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.keycloak.social.weixin.egress.wechat.mp.models; | ||
|
||
public class ActionInfo { | ||
public Scene scene; | ||
|
||
public ActionInfo(Scene scene) { | ||
this.scene = scene; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/keycloak/social/weixin/egress/wechat/mp/models/Scene.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.keycloak.social.weixin.egress.wechat.mp.models; | ||
|
||
public class Scene { | ||
public String scene_str; | ||
|
||
public Scene(String scene_str) { | ||
this.scene_str = scene_str; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/keycloak/social/weixin/egress/wechat/mp/models/TicketRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.keycloak.social.weixin.egress.wechat.mp.models; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public class TicketRequest { | ||
public Number expire_seconds; | ||
public String action_name; | ||
public ActionInfo action_info; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/keycloak/social/weixin/egress/wechat/mp/models/TicketResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.keycloak.social.weixin.egress.wechat.mp.models; | ||
|
||
public class TicketResponse { | ||
public String ticket; | ||
public Number expire_seconds; | ||
public String url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters