记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
617ab3aa
Commit
617ab3aa
authored
Dec 15, 2021
by
张国柄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
~DEL.API:原H5根据wechat.code换取openid;
parent
f46be968
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
224 additions
and
230 deletions
+224
-230
WechatMaConfigure.java
.../com/liquidnet/service/adam/config/WechatMaConfigure.java
+146
-146
AdamLoginController.java
...iquidnet/service/adam/controller/AdamLoginController.java
+47
-53
AdamWechatService.java
...com/liquidnet/service/adam/service/AdamWechatService.java
+31
-31
No files found.
liquidnet-bus-service/liquidnet-service-adam/liquidnet-service-adam-impl/src/main/java/com/liquidnet/service/adam/config/WechatMaConfigure.java
View file @
617ab3aa
package
com
.
liquidnet
.
service
.
adam
.
config
;
//
package com.liquidnet.service.adam.config;
//
import
cn.binarywang.wx.miniapp.api.WxMaService
;
//
import cn.binarywang.wx.miniapp.api.WxMaService;
import
cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl
;
//
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import
cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl
;
//
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import
cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl
;
//
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import
me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps
;
//
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import
org.springframework.beans.factory.annotation.Autowired
;
//
import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
//
import org.springframework.beans.factory.annotation.Value;
import
org.springframework.context.annotation.Configuration
;
//
import org.springframework.context.annotation.Configuration;
import
org.springframework.data.redis.core.StringRedisTemplate
;
//
import org.springframework.data.redis.core.StringRedisTemplate;
//
import
javax.annotation.PostConstruct
;
//
import javax.annotation.PostConstruct;
//
@Configuration
//
@Configuration
public
class
WechatMaConfigure
{
//
public class WechatMaConfigure {
private
static
String
appletAppidZhengzai
;
//
private static String appletAppidZhengzai;
private
static
String
appletSecretZhengzai
;
//
private static String appletSecretZhengzai;
//
private
static
String
appletAppidStrawberry
;
//
private static String appletAppidStrawberry;
private
static
String
appletSecretStrawberry
;
//
private static String appletSecretStrawberry;
//
private
static
String
appletAppidFive
;
//
private static String appletAppidFive;
private
static
String
appletSecretFive
;
//
private static String appletSecretFive;
//
private
static
String
appletAppidMdsk
;
//
private static String appletAppidMdsk;
private
static
String
appletSecretMdsk
;
//
private static String appletSecretMdsk;
//
@Value
(
"${liquidnet.wechat.applet.strawberry.appid}"
)
//
@Value("${liquidnet.wechat.applet.strawberry.appid}")
public
void
setAppletAppidZhengzai
(
String
appletAppidZhengzai
)
{
//
public void setAppletAppidZhengzai(String appletAppidZhengzai) {
WechatMaConfigure
.
appletAppidZhengzai
=
appletAppidZhengzai
;
//
WechatMaConfigure.appletAppidZhengzai = appletAppidZhengzai;
}
//
}
//
@Value
(
"${liquidnet.wechat.applet.strawberry.secret}"
)
//
@Value("${liquidnet.wechat.applet.strawberry.secret}")
public
void
setAppletSecretZhengzai
(
String
appletSecretZhengzai
)
{
//
public void setAppletSecretZhengzai(String appletSecretZhengzai) {
WechatMaConfigure
.
appletSecretZhengzai
=
appletSecretZhengzai
;
//
WechatMaConfigure.appletSecretZhengzai = appletSecretZhengzai;
}
//
}
//
@Value
(
"${liquidnet.wechat.applet.strawberry.appid}"
)
//
@Value("${liquidnet.wechat.applet.strawberry.appid}")
public
void
setAppletAppidStrawberry
(
String
appletAppidStrawberry
)
{
//
public void setAppletAppidStrawberry(String appletAppidStrawberry) {
WechatMaConfigure
.
appletAppidStrawberry
=
appletAppidStrawberry
;
//
WechatMaConfigure.appletAppidStrawberry = appletAppidStrawberry;
}
//
}
//
@Value
(
"${liquidnet.wechat.applet.strawberry.secret}"
)
//
@Value("${liquidnet.wechat.applet.strawberry.secret}")
public
void
setAppletSecretStrawberry
(
String
appletSecretStrawberry
)
{
//
public void setAppletSecretStrawberry(String appletSecretStrawberry) {
WechatMaConfigure
.
appletSecretStrawberry
=
appletSecretStrawberry
;
//
WechatMaConfigure.appletSecretStrawberry = appletSecretStrawberry;
}
//
}
//
@Value
(
"${liquidnet.wechat.applet.five.appid}"
)
//
@Value("${liquidnet.wechat.applet.five.appid}")
public
void
setAppletAppidFive
(
String
appletAppidFive
)
{
//
public void setAppletAppidFive(String appletAppidFive) {
WechatMaConfigure
.
appletAppidFive
=
appletAppidFive
;
//
WechatMaConfigure.appletAppidFive = appletAppidFive;
}
//
}
//
@Value
(
"${liquidnet.wechat.applet.five.secret}"
)
//
@Value("${liquidnet.wechat.applet.five.secret}")
public
void
setAppletSecretFive
(
String
appletSecretFive
)
{
//
public void setAppletSecretFive(String appletSecretFive) {
WechatMaConfigure
.
appletSecretFive
=
appletSecretFive
;
//
WechatMaConfigure.appletSecretFive = appletSecretFive;
}
//
}
//
@Value
(
"${liquidnet.wechat.applet.mdsk.appid}"
)
//
@Value("${liquidnet.wechat.applet.mdsk.appid}")
public
void
setAppletAppidMdsk
(
String
appletAppidMdsk
)
{
//
public void setAppletAppidMdsk(String appletAppidMdsk) {
WechatMaConfigure
.
appletAppidMdsk
=
appletAppidMdsk
;
//
WechatMaConfigure.appletAppidMdsk = appletAppidMdsk;
}
//
}
//
@Value
(
"${liquidnet.wechat.applet.mdsk.secret}"
)
//
@Value("${liquidnet.wechat.applet.mdsk.secret}")
public
void
setAppletSecretMdsk
(
String
appletSecretMdsk
)
{
//
public void setAppletSecretMdsk(String appletSecretMdsk) {
WechatMaConfigure
.
appletSecretMdsk
=
appletSecretMdsk
;
//
WechatMaConfigure.appletSecretMdsk = appletSecretMdsk;
}
//
}
//
private
WxMaService
wxMaAppletZhengzaiService
;
//
private WxMaService wxMaAppletZhengzaiService;
private
WxMaService
wxMaAppletStrawberryService
;
//
private WxMaService wxMaAppletStrawberryService;
private
WxMaService
wxMaAppletFiveService
;
//
private WxMaService wxMaAppletFiveService;
private
WxMaService
wxMaAppletMdskService
;
//
private WxMaService wxMaAppletMdskService;
//
@Autowired
//
@Autowired
private
StringRedisTemplate
stringRedisTemplate
;
//
private StringRedisTemplate stringRedisTemplate;
//
@PostConstruct
//
@PostConstruct
public
void
init
()
{
//
public void init() {
wxMaAppletZhengzaiService
=
new
WxMaServiceImpl
()
{
//
wxMaAppletZhengzaiService = new WxMaServiceImpl() {
{
//
{
RedisTemplateWxRedisOps
redisTemplateWxRedisOps
=
new
RedisTemplateWxRedisOps
(
stringRedisTemplate
);
//
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl
wxMaDefaultConfig
=
new
WxMaRedisBetterConfigImpl
(
redisTemplateWxRedisOps
,
"adam:accessToken:applet:zhengzai"
);
//
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "adam:accessToken:applet:zhengzai");
//
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
//
//
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig
.
setAppid
(
appletAppidZhengzai
);
//
wxMaDefaultConfig.setAppid(appletAppidZhengzai);
wxMaDefaultConfig
.
setSecret
(
appletSecretZhengzai
);
//
wxMaDefaultConfig.setSecret(appletSecretZhengzai);
wxMaDefaultConfig
.
setMsgDataFormat
(
"JSON"
);
//
wxMaDefaultConfig.setMsgDataFormat("JSON");
//
this
.
setWxMaConfig
(
wxMaDefaultConfig
);
//
this.setWxMaConfig(wxMaDefaultConfig);
}
//
}
};
//
};
wxMaAppletStrawberryService
=
new
WxMaServiceImpl
()
{
//
wxMaAppletStrawberryService = new WxMaServiceImpl() {
{
//
{
RedisTemplateWxRedisOps
redisTemplateWxRedisOps
=
new
RedisTemplateWxRedisOps
(
stringRedisTemplate
);
//
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl
wxMaDefaultConfig
=
new
WxMaRedisBetterConfigImpl
(
redisTemplateWxRedisOps
,
"sweet:accessToken:applet:strawberry"
);
//
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:strawberry");
//
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
//
//
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig
.
setAppid
(
appletAppidStrawberry
);
//
wxMaDefaultConfig.setAppid(appletAppidStrawberry);
wxMaDefaultConfig
.
setSecret
(
appletSecretStrawberry
);
//
wxMaDefaultConfig.setSecret(appletSecretStrawberry);
wxMaDefaultConfig
.
setMsgDataFormat
(
"JSON"
);
//
wxMaDefaultConfig.setMsgDataFormat("JSON");
//
this
.
setWxMaConfig
(
wxMaDefaultConfig
);
//
this.setWxMaConfig(wxMaDefaultConfig);
}
//
}
};
//
};
wxMaAppletFiveService
=
new
WxMaServiceImpl
()
{
//
wxMaAppletFiveService = new WxMaServiceImpl() {
{
//
{
RedisTemplateWxRedisOps
redisTemplateWxRedisOps
=
new
RedisTemplateWxRedisOps
(
stringRedisTemplate
);
//
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl
wxMaDefaultConfig
=
new
WxMaRedisBetterConfigImpl
(
redisTemplateWxRedisOps
,
"sweet:accessToken:applet:five"
);
//
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:five");
//
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
//
//
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig
.
setAppid
(
appletAppidFive
);
//
wxMaDefaultConfig.setAppid(appletAppidFive);
wxMaDefaultConfig
.
setSecret
(
appletSecretFive
);
//
wxMaDefaultConfig.setSecret(appletSecretFive);
wxMaDefaultConfig
.
setMsgDataFormat
(
"JSON"
);
//
wxMaDefaultConfig.setMsgDataFormat("JSON");
//
this
.
setWxMaConfig
(
wxMaDefaultConfig
);
//
this.setWxMaConfig(wxMaDefaultConfig);
}
//
}
};
//
};
wxMaAppletMdskService
=
new
WxMaServiceImpl
()
{
//
wxMaAppletMdskService = new WxMaServiceImpl() {
{
//
{
RedisTemplateWxRedisOps
redisTemplateWxRedisOps
=
new
RedisTemplateWxRedisOps
(
stringRedisTemplate
);
//
RedisTemplateWxRedisOps redisTemplateWxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
WxMaRedisBetterConfigImpl
wxMaDefaultConfig
=
new
WxMaRedisBetterConfigImpl
(
redisTemplateWxRedisOps
,
"sweet:accessToken:applet:mdsk"
);
//
WxMaRedisBetterConfigImpl wxMaDefaultConfig = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps, "sweet:accessToken:applet:mdsk");
//
// WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
//
//
WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
wxMaDefaultConfig
.
setAppid
(
appletAppidMdsk
);
//
wxMaDefaultConfig.setAppid(appletAppidMdsk);
wxMaDefaultConfig
.
setSecret
(
appletSecretMdsk
);
//
wxMaDefaultConfig.setSecret(appletSecretMdsk);
wxMaDefaultConfig
.
setMsgDataFormat
(
"JSON"
);
//
wxMaDefaultConfig.setMsgDataFormat("JSON");
//
this
.
setWxMaConfig
(
wxMaDefaultConfig
);
//
this.setWxMaConfig(wxMaDefaultConfig);
}
//
}
};
//
};
}
//
}
//
public
WxMaService
getWxMaService
(
Integer
anum
)
{
//
public WxMaService getWxMaService(Integer anum) {
switch
(
anum
)
{
//
switch (anum) {
case
1
:
//
case 1:
return
wxMaAppletZhengzaiService
;
//
return wxMaAppletZhengzaiService;
case
2
:
//
case 2:
return
wxMaAppletStrawberryService
;
//
return wxMaAppletStrawberryService;
case
3
:
//
case 3:
return
wxMaAppletFiveService
;
//
return wxMaAppletFiveService;
case
4
:
//
case 4:
return
wxMaAppletMdskService
;
//
return wxMaAppletMdskService;
}
//
}
return
null
;
//
return null;
}
//
}
}
//
}
liquidnet-bus-service/liquidnet-service-adam/liquidnet-service-adam-impl/src/main/java/com/liquidnet/service/adam/controller/AdamLoginController.java
View file @
617ab3aa
package
com
.
liquidnet
.
service
.
adam
.
controller
;
package
com
.
liquidnet
.
service
.
adam
.
controller
;
import
cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult
;
import
cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.dypnsapi.model.v20170525.GetMobileRequest
;
import
com.aliyuncs.dypnsapi.model.v20170525.GetMobileRequest
;
import
com.aliyuncs.dypnsapi.model.v20170525.GetMobileResponse
;
import
com.aliyuncs.dypnsapi.model.v20170525.GetMobileResponse
;
import
com.aliyuncs.exceptions.ClientException
;
import
com.aliyuncs.exceptions.ClientException
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.github.xiaoymin.knife4j.annotations.ApiOperationSupport
;
import
com.github.xiaoymin.knife4j.annotations.ApiOperationSupport
;
import
com.github.xiaoymin.knife4j.annotations.ApiSupport
;
import
com.github.xiaoymin.knife4j.annotations.ApiSupport
;
...
@@ -16,12 +13,10 @@ import com.liquidnet.common.sms.processor.SmsProcessor;
...
@@ -16,12 +13,10 @@ import com.liquidnet.common.sms.processor.SmsProcessor;
import
com.liquidnet.commons.lang.constant.LnsEnum
;
import
com.liquidnet.commons.lang.constant.LnsEnum
;
import
com.liquidnet.commons.lang.core.JwtValidator
;
import
com.liquidnet.commons.lang.core.JwtValidator
;
import
com.liquidnet.commons.lang.util.*
;
import
com.liquidnet.commons.lang.util.*
;
import
com.liquidnet.service.adam.constant.AdamWechatConst
;
import
com.liquidnet.service.adam.dto.AdamThirdPartParam
;
import
com.liquidnet.service.adam.dto.AdamThirdPartParam
;
import
com.liquidnet.service.adam.dto.vo.AdamLoginInfoVo
;
import
com.liquidnet.service.adam.dto.vo.AdamLoginInfoVo
;
import
com.liquidnet.service.adam.dto.vo.AdamUserInfoVo
;
import
com.liquidnet.service.adam.dto.vo.AdamUserInfoVo
;
import
com.liquidnet.service.adam.service.AdamRdmService
;
import
com.liquidnet.service.adam.service.AdamRdmService
;
import
com.liquidnet.service.adam.service.AdamWechatService
;
import
com.liquidnet.service.adam.service.IAdamUserService
;
import
com.liquidnet.service.adam.service.IAdamUserService
;
import
com.liquidnet.service.base.ErrorMapping
;
import
com.liquidnet.service.base.ErrorMapping
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.ResponseDto
;
...
@@ -31,7 +26,6 @@ import io.swagger.annotations.ApiImplicitParam;
...
@@ -31,7 +26,6 @@ import io.swagger.annotations.ApiImplicitParam;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
me.chanjar.weixin.common.error.WxErrorException
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -75,8 +69,8 @@ public class AdamLoginController {
...
@@ -75,8 +69,8 @@ public class AdamLoginController {
IAdamUserService
adamUserService
;
IAdamUserService
adamUserService
;
@Autowired
@Autowired
SmsProcessor
smsProcessor
;
SmsProcessor
smsProcessor
;
@Autowired
//
@Autowired
AdamWechatService
adamWechatService
;
//
AdamWechatService adamWechatService;
@Value
(
"${liquidnet.reviewer.app-login.mobile}"
)
@Value
(
"${liquidnet.reviewer.app-login.mobile}"
)
private
String
reviewMobile
;
private
String
reviewMobile
;
...
@@ -398,51 +392,51 @@ public class AdamLoginController {
...
@@ -398,51 +392,51 @@ public class AdamLoginController {
return
ResponseDto
.
success
(
LocalDateTime
.
now
().
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
());
return
ResponseDto
.
success
(
LocalDateTime
.
now
().
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
());
}
}
@ApiOperationSupport
(
order
=
10
)
//
@ApiOperationSupport(order = 10)
@ApiOperation
(
value
=
"微信小程序登录凭证校验"
,
notes
=
"这里仅用于获取OPENID使用。登录凭证校验。通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。更多使用方法详见 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html"
)
//
@ApiOperation(value = "微信小程序登录凭证校验", notes = "这里仅用于获取OPENID使用。登录凭证校验。通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。更多使用方法详见 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html")
@GetMapping
(
value
=
{
"wxa/code2session"
})
//
@GetMapping(value = {"wxa/code2session"})
public
ResponseDto
<
String
>
wxaCode2Session
(
@RequestParam
String
jsCode
)
{
//
public ResponseDto<String> wxaCode2Session(@RequestParam String jsCode) {
String
openId
=
null
,
respJStr
=
null
;
//
String openId = null, respJStr = null;
try
{
//
try {
String
url
=
AdamWechatConst
.
API_URL_JS_CODE2SESSION
.
replace
(
"APPID"
,
AdamWechatConst
.
zhengzaiAppletAppid
)
//
String url = AdamWechatConst.API_URL_JS_CODE2SESSION.replace("APPID", AdamWechatConst.zhengzaiAppletAppid)
.
replace
(
"SECRET"
,
AdamWechatConst
.
zhengzaiAppletSecret
).
replace
(
"JSCODE"
,
jsCode
);
//
.replace("SECRET", AdamWechatConst.zhengzaiAppletSecret).replace("JSCODE", jsCode);
log
.
debug
(
"jsCode={},url={}"
,
jsCode
,
url
);
//
log.debug("jsCode={},url={}", jsCode, url);
respJStr
=
HttpUtil
.
get
(
url
,
null
);
//
respJStr = HttpUtil.get(url, null);
JsonNode
respJNode
=
JsonUtils
.
fromJson
(
respJStr
,
JsonNode
.
class
),
respErrcode
;
//
JsonNode respJNode = JsonUtils.fromJson(respJStr, JsonNode.class), respErrcode;
if
(
null
==
respJNode
||
(((
respErrcode
=
respJNode
.
get
(
"errcode"
))
!=
null
)
&&
!
"0"
.
equalsIgnoreCase
(
respErrcode
.
asText
())))
{
//
if (null == respJNode || (((respErrcode = respJNode.get("errcode")) != null) && !"0".equalsIgnoreCase(respErrcode.asText()))) {
log
.
warn
(
"WX.API调用失败[{}]"
,
respJStr
);
//
log.warn("WX.API调用失败[{}]", respJStr);
return
ResponseDto
.
success
(
null
);
//
return ResponseDto.success(null);
}
//
}
openId
=
respJNode
.
get
(
"openid"
).
asText
();
//
openId = respJNode.get("openid").asText();
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
log
.
error
(
"WX.API调用异常[jsCode:{},respJStr={}]"
,
jsCode
,
respJStr
,
e
);
//
log.error("WX.API调用异常[jsCode:{},respJStr={}]", jsCode, respJStr, e);
}
//
}
log
.
debug
(
"jsCode={},respJStr={}"
,
jsCode
,
respJStr
);
//
log.debug("jsCode={},respJStr={}", jsCode, respJStr);
return
ResponseDto
.
success
(
openId
);
//
return ResponseDto.success(openId);
}
//
}
//
@ApiOperationSupport
(
order
=
11
)
//
@ApiOperationSupport(order = 11)
@ApiOperation
(
value
=
"微信网站应用登录"
,
notes
=
"这里仅用于获取OPENID使用。方法详见 https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html"
)
//
@ApiOperation(value = "微信网站应用登录", notes = "这里仅用于获取OPENID使用。方法详见 https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html")
@GetMapping
(
value
=
{
"wx/oauth2/access_token"
})
//
@GetMapping(value = {"wx/oauth2/access_token"})
public
ResponseDto
<
String
>
wxOauth2AccessToken
(
@RequestParam
String
code
)
{
//
public ResponseDto<String> wxOauth2AccessToken(@RequestParam String code) {
String
openId
=
null
,
respJStr
=
null
;
//
String openId = null, respJStr = null;
try
{
//
try {
String
url
=
AdamWechatConst
.
API_URL_OAUTH2_ACCESS_TOKEN
.
replace
(
"APPID"
,
AdamWechatConst
.
zhengzaiServiceAppid
)
//
String url = AdamWechatConst.API_URL_OAUTH2_ACCESS_TOKEN.replace("APPID", AdamWechatConst.zhengzaiServiceAppid)
.
replace
(
"SECRET"
,
AdamWechatConst
.
zhengzaiServiceSecret
).
replace
(
"CODE"
,
code
);
//
.replace("SECRET", AdamWechatConst.zhengzaiServiceSecret).replace("CODE", code);
log
.
debug
(
"code={},url={}"
,
code
,
url
);
//
log.debug("code={},url={}", code, url);
respJStr
=
HttpUtil
.
get
(
url
,
null
);
//
respJStr = HttpUtil.get(url, null);
JsonNode
respJNode
=
JsonUtils
.
fromJson
(
respJStr
,
JsonNode
.
class
),
respErrcode
;
//
JsonNode respJNode = JsonUtils.fromJson(respJStr, JsonNode.class), respErrcode;
if
(
null
==
respJNode
||
(((
respErrcode
=
respJNode
.
get
(
"errcode"
))
!=
null
)
&&
!
"0"
.
equalsIgnoreCase
(
respErrcode
.
asText
())))
{
//
if (null == respJNode || (((respErrcode = respJNode.get("errcode")) != null) && !"0".equalsIgnoreCase(respErrcode.asText()))) {
log
.
warn
(
"WX.API调用失败[{}]"
,
respJStr
);
//
log.warn("WX.API调用失败[{}]", respJStr);
return
ResponseDto
.
success
(
null
);
//
return ResponseDto.success(null);
}
//
}
openId
=
respJNode
.
get
(
"openid"
).
asText
();
//
openId = respJNode.get("openid").asText();
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
log
.
error
(
"WX.API调用异常[jsCode:{},respJStr={}]"
,
code
,
respJStr
,
e
);
//
log.error("WX.API调用异常[jsCode:{},respJStr={}]", code, respJStr, e);
}
//
}
log
.
debug
(
"code={},respJStr={}"
,
code
,
respJStr
);
//
log.debug("code={},respJStr={}", code, respJStr);
return
ResponseDto
.
success
(
openId
);
//
return ResponseDto.success(openId);
}
//
}
/* ---------------------------- Internal Method ---------------------------- */
/* ---------------------------- Internal Method ---------------------------- */
/* ---------------------------- Internal Method ---------------------------- */
/* ---------------------------- Internal Method ---------------------------- */
...
...
liquidnet-bus-service/liquidnet-service-adam/liquidnet-service-adam-impl/src/main/java/com/liquidnet/service/adam/service/AdamWechatService.java
View file @
617ab3aa
package
com
.
liquidnet
.
service
.
adam
.
service
;
//
package com.liquidnet.service.adam.service;
//
import
cn.binarywang.wx.miniapp.api.WxMaService
;
//
import cn.binarywang.wx.miniapp.api.WxMaService;
import
cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult
;
//
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import
cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo
;
//
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import
cn.binarywang.wx.miniapp.bean.WxMaUserInfo
;
//
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import
com.liquidnet.service.adam.config.WechatMaConfigure
;
//
import com.liquidnet.service.adam.config.WechatMaConfigure;
import
me.chanjar.weixin.common.error.WxErrorException
;
//
import me.chanjar.weixin.common.error.WxErrorException;
import
org.springframework.beans.factory.annotation.Autowired
;
//
import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
//
import org.springframework.stereotype.Service;
//
@Service
//
@Service
public
class
AdamWechatService
{
//
public class AdamWechatService {
@Autowired
//
@Autowired
WechatMaConfigure
wechatMaConfigure
;
//
WechatMaConfigure wechatMaConfigure;
//
public
WxMaJscode2SessionResult
sessionInfo
(
String
code
,
Integer
anum
)
throws
WxErrorException
{
//
public WxMaJscode2SessionResult sessionInfo(String code, Integer anum) throws WxErrorException {
WxMaService
wxMaService
=
wechatMaConfigure
.
getWxMaService
(
anum
);
//
WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
return
wxMaService
.
getUserService
().
getSessionInfo
(
code
);
//
return wxMaService.getUserService().getSessionInfo(code);
}
//
}
//
public
WxMaUserInfo
userInfo
(
String
sessionKey
,
String
encryptedData
,
String
iv
,
Integer
anum
)
{
//
public WxMaUserInfo userInfo(String sessionKey, String encryptedData, String iv, Integer anum) {
WxMaService
wxMaService
=
wechatMaConfigure
.
getWxMaService
(
anum
);
//
WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
return
wxMaService
.
getUserService
().
getUserInfo
(
sessionKey
,
encryptedData
,
iv
);
//
return wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
}
//
}
//
public
WxMaPhoneNumberInfo
phoneNumberInfo
(
String
sessionKey
,
String
encryptedData
,
String
iv
,
Integer
anum
)
{
//
public WxMaPhoneNumberInfo phoneNumberInfo(String sessionKey, String encryptedData, String iv, Integer anum) {
WxMaService
wxMaService
=
wechatMaConfigure
.
getWxMaService
(
anum
);
//
WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
return
wxMaService
.
getUserService
().
getPhoneNoInfo
(
sessionKey
,
encryptedData
,
iv
);
//
return wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
}
//
}
}
//
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment