Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
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
YZG
yzg-util
Commits
d066ae4f
Commit
d066ae4f
authored
Jul 14, 2022
by
xianjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加返回转byte
parent
b903cfcb
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
266 additions
and
87 deletions
+266
-87
HttpHelper.java
...src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
+58
-0
WxXcxByteArrayRequest.java
...ava/com/yanzuoguang/wxxcx/base/WxXcxByteArrayRequest.java
+15
-0
WxXcxRequestByteArrayImpl.java
...com/yanzuoguang/wxxcx/base/WxXcxRequestByteArrayImpl.java
+47
-0
WxXcxResponseArrayByteConvert.java
...yanzuoguang/wxxcx/base/WxXcxResponseArrayByteConvert.java
+15
-0
WxXcxUrlSchemeGenerateJumpWxaReq.java
...odeorlink/urlscheme/WxXcxUrlSchemeGenerateJumpWxaReq.java
+3
-1
WxXcxUrlSchemeGenerateReq.java
...wxxcx/codeorlink/urlscheme/WxXcxUrlSchemeGenerateReq.java
+4
-12
WxXcxUrlSchemeGenerateRequest.java
...x/codeorlink/urlscheme/WxXcxUrlSchemeGenerateRequest.java
+10
-6
WxXcxWxaCodeCreateQrCodeReq.java
...wxxcx/codeorlink/wxacode/WxXcxWxaCodeCreateQrCodeReq.java
+3
-1
WxXcxWxaCodeCreateQrCodeRequest.java
...x/codeorlink/wxacode/WxXcxWxaCodeCreateQrCodeRequest.java
+2
-1
WxXcxWxaCodeGetUnlimitedReq.java
...wxxcx/codeorlink/wxacode/WxXcxWxaCodeGetUnlimitedReq.java
+1
-24
WxXcxWxaCodeGetUnlimitedRequest.java
...x/codeorlink/wxacode/WxXcxWxaCodeGetUnlimitedRequest.java
+11
-10
WxXcxWxaCodeGetUnlimitedRes.java
...wxxcx/codeorlink/wxacode/WxXcxWxaCodeGetUnlimitedRes.java
+5
-22
WxXcxWxaCodeGetUnlimitedServiceImpl.java
...ode/service/impl/WxXcxWxaCodeGetUnlimitedServiceImpl.java
+5
-4
WxXcxAuthCode2SessionService.java
...ang/wxxcx/login/service/WxXcxAuthCode2SessionService.java
+1
-3
WxXcxAuthCode2SessionServiceImpl.java
.../login/service/impl/WxXcxAuthCode2SessionServiceImpl.java
+1
-3
WeChatUtil.java
...src/main/java/com/yanzuoguang/wxxcx/utils/WeChatUtil.java
+85
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
View file @
d066ae4f
...
@@ -262,6 +262,47 @@ public class HttpHelper {
...
@@ -262,6 +262,47 @@ public class HttpHelper {
return
result
.
toString
();
return
result
.
toString
();
}
}
/**
* 发送POST请求,当请求失败时,抛出异常或返回空字符串
*
* @param httpConn 链接信息
* @param jsonString 请求参数,json字符串。
* @return 远程响应结果
*/
public
static
byte
[]
postResultByteArray
(
HttpURLConnection
httpConn
,
String
jsonString
)
throws
IOException
{
// 返回的结果
byte
[]
byteArray
;
PrintWriter
out
=
null
;
// 处理请求参数
String
params
=
""
;
try
{
params
=
jsonString
;
// 获取HttpURLConnection对象对应的输出流
out
=
new
PrintWriter
(
httpConn
.
getOutputStream
());
// 发送请求参数
out
.
write
(
params
);
// flush输出流的缓冲
out
.
flush
();
int
returnCode
=
httpConn
.
getResponseCode
();
if
(
returnCode
==
HttpURLConnection
.
HTTP_OK
)
{
byteArray
=
readByteArray
(
httpConn
.
getInputStream
());
}
else
{
throw
new
HttpCodeException
(
StringHelper
.
toString
(
returnCode
),
httpConn
.
getResponseMessage
());
}
}
catch
(
HttpCodeException
ex
)
{
throw
ex
;
}
catch
(
Exception
ex
)
{
byteArray
=
readByteArray
(
httpConn
.
getErrorStream
());
throw
new
HttpCodeException
(
StringHelper
.
toString
(
httpConn
.
getResponseCode
()),
ex
.
getMessage
(),
ex
);
}
finally
{
if
(
out
!=
null
)
{
out
.
close
();
}
}
return
byteArray
;
}
/**
/**
* 发送GET请求,当请求失败时,抛出异常或返回空字符串
* 发送GET请求,当请求失败时,抛出异常或返回空字符串
*
*
...
@@ -320,6 +361,23 @@ public class HttpHelper {
...
@@ -320,6 +361,23 @@ public class HttpHelper {
return
in
;
return
in
;
}
}
/**
* 读取数据流
*
* @param input 流
* @return 读取的缓存流
* @throws IOException IO异常
*/
public
static
byte
[]
readByteArray
(
InputStream
input
)
throws
IOException
{
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
*
4
];
int
n
=
0
;
while
(-
1
!=
(
n
=
input
.
read
(
buffer
)))
{
output
.
write
(
buffer
,
0
,
n
);
}
return
output
.
toByteArray
();
}
/**
/**
* 下载文件
* 下载文件
*
*
...
...
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/base/WxXcxByteArrayRequest.java
0 → 100644
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
base
;
/**
* @author 李贤军
*/
public
interface
WxXcxByteArrayRequest
{
/**
* 请求其他
*
* @param req 请求后端实现
* @param convert 转换参数
* @return 返回请求流
*/
byte
[]
request
(
WxXcxRequestUrl
req
,
WxXcxResponseArrayByteConvert
convert
);
}
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/base/WxXcxRequestByteArrayImpl.java
0 → 100644
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
base
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.net.HttpURLConnection
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author 李贤军
*/
public
class
WxXcxRequestByteArrayImpl
implements
WxXcxByteArrayRequest
{
@Value
(
"${yzg.wx.xwx.charset:utf-8}"
)
private
String
defaultCharSet
;
@Override
public
byte
[]
request
(
WxXcxRequestUrl
req
,
WxXcxResponseArrayByteConvert
convert
)
{
String
url
=
req
.
getUrl
();
// String charSet = defaultCharSet;
String
charSet
=
"utf-8"
;
Map
<
String
,
String
>
header
;
if
(
req
instanceof
WxXcxRequestHeader
)
{
// 设置header信息
header
=
((
WxXcxRequestHeader
)
req
).
getHeader
();
}
else
{
header
=
new
HashMap
<>(
0
);
}
byte
[]
response
=
null
;
try
{
if
(
req
instanceof
WxXcxRequestPostFormData
)
{
WxXcxRequestPostFormData
post
=
(
WxXcxRequestPostFormData
)
req
;
HttpURLConnection
conn
=
HttpHelper
.
getConn
(
url
,
header
);
response
=
HttpHelper
.
postResultByteArray
(
conn
,
post
.
getPost
());
}
else
if
(
req
instanceof
WxXcxRequestPostApplication
)
{
WxXcxRequestPostApplication
post
=
(
WxXcxRequestPostApplication
)
req
;
// 打开URL连接
java
.
net
.
HttpURLConnection
httpConn
=
HttpHelper
.
getConn
(
url
,
header
,
true
);
response
=
HttpHelper
.
postResultByteArray
(
httpConn
,
post
.
getPost
());
}
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
ex
);
}
return
convert
.
getResponse
(
response
);
}
}
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/base/WxXcxResponseArrayByteConvert.java
0 → 100644
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
base
;
/**
* @author 李贤军
*/
public
interface
WxXcxResponseArrayByteConvert
{
/**
* 将字符串转换为结果
*
* @param response 字符串
* @return 实体结果
*/
byte
[]
getResponse
(
byte
[]
response
);
}
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/urlscheme/WxXcxUrlSchemeGenerateJumpWxaReq.java
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
urlscheme
;
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
urlscheme
;
import
java.io.Serializable
;
/**
/**
* 获取小程序 scheme 码,适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放
* 获取小程序 scheme 码,适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放
*
*
* @author 李贤军
* @author 李贤军
*/
*/
public
class
WxXcxUrlSchemeGenerateJumpWxaReq
{
public
class
WxXcxUrlSchemeGenerateJumpWxaReq
implements
Serializable
{
/**
/**
* 通过 scheme 码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带 query。path 为空时会跳转小程序主页
* 通过 scheme 码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带 query。path 为空时会跳转小程序主页
*/
*/
...
...
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/urlscheme/WxXcxUrlSchemeGenerateReq.java
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
urlscheme
;
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
urlscheme
;
import
java.io.Serializable
;
/**
/**
* 获取小程序 scheme 码 请求
* 获取小程序 scheme 码 请求
* 适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放
* 适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放
*
*
* @author 李贤军
* @author 李贤军
*/
*/
public
class
WxXcxUrlSchemeGenerateReq
{
public
class
WxXcxUrlSchemeGenerateReq
implements
Serializable
{
/**
* 接口调用凭证
*/
private
String
access_token
;
/**
/**
* 跳转到的目标小程序信息。
* 跳转到的目标小程序信息。
*/
*/
...
@@ -28,13 +27,6 @@ public class WxXcxUrlSchemeGenerateReq {
...
@@ -28,13 +27,6 @@ public class WxXcxUrlSchemeGenerateReq {
*/
*/
private
int
expire_interval
;
private
int
expire_interval
;
public
String
getAccess_token
()
{
return
access_token
;
}
public
void
setAccess_token
(
String
access_token
)
{
this
.
access_token
=
access_token
;
}
public
WxXcxUrlSchemeGenerateJumpWxaReq
getJump_wxa
()
{
public
WxXcxUrlSchemeGenerateJumpWxaReq
getJump_wxa
()
{
return
jump_wxa
;
return
jump_wxa
;
...
...
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/urlscheme/WxXcxUrlSchemeGenerateRequest.java
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
urlscheme
;
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
urlscheme
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.TypeReference
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.wxxcx.base.*
;
import
com.yanzuoguang.wxxcx.base.*
;
import
com.yanzuoguang.wxxcx.codeorlink.urlscheme.service.WxXcxUrlSchemeGenerateService
;
import
com.yanzuoguang.wxxcx.codeorlink.urlscheme.service.impl.WxXcxUrlSchemeGenerateServiceImpl
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* 获取小程序 scheme 码 转换
* 获取小程序 scheme 码 转换
...
@@ -13,7 +20,7 @@ import com.yanzuoguang.wxxcx.base.*;
...
@@ -13,7 +20,7 @@ import com.yanzuoguang.wxxcx.base.*;
*
*
* @author 李贤军
* @author 李贤军
*/
*/
public
class
WxXcxUrlSchemeGenerateRequest
implements
WxXcxRequestUrl
,
WxXcxRequestUrlPara
,
WxXcxRequestPost
FormData
{
public
class
WxXcxUrlSchemeGenerateRequest
implements
WxXcxRequestUrl
,
WxXcxRequestUrlPara
,
WxXcxRequestPost
Application
{
private
final
WxXcxConfig
wxXcxConfig
;
private
final
WxXcxConfig
wxXcxConfig
;
private
final
WxXcxRequest
wxXcxRequest
;
private
final
WxXcxRequest
wxXcxRequest
;
...
@@ -39,11 +46,10 @@ public class WxXcxUrlSchemeGenerateRequest implements WxXcxRequestUrl, WxXcxRequ
...
@@ -39,11 +46,10 @@ public class WxXcxUrlSchemeGenerateRequest implements WxXcxRequestUrl, WxXcxRequ
@Override
@Override
public
String
getPost
()
{
public
String
getPost
()
{
return
HttpHelper
.
getUrlParameter
(
req
);
return
JSON
.
toJSONString
(
req
);
}
}
public
WxXcxUrlSchemeGenerateRes
getResponse
()
{
public
WxXcxUrlSchemeGenerateRes
getResponse
()
{
checkParam
(
req
);
return
this
.
wxXcxRequest
.
request
(
this
,
response
->
{
return
this
.
wxXcxRequest
.
request
(
this
,
response
->
{
WxXcxUrlSchemeGenerateRes
ret
=
JsonHelper
.
deserialize
(
response
,
new
TypeReference
<
WxXcxUrlSchemeGenerateRes
>()
{
WxXcxUrlSchemeGenerateRes
ret
=
JsonHelper
.
deserialize
(
response
,
new
TypeReference
<
WxXcxUrlSchemeGenerateRes
>()
{
});
});
...
@@ -52,7 +58,5 @@ public class WxXcxUrlSchemeGenerateRequest implements WxXcxRequestUrl, WxXcxRequ
...
@@ -52,7 +58,5 @@ public class WxXcxUrlSchemeGenerateRequest implements WxXcxRequestUrl, WxXcxRequ
});
});
}
}
private
void
checkParam
(
WxXcxUrlSchemeGenerateReq
req
)
{
CheckerHelper
.
newInstance
().
notBlankCheck
(
WxXcxAccessTokenField
.
FIELD_ACCESS_TOKEN
,
req
.
getAccess_token
()).
checkException
();
}
}
}
\ No newline at end of file
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/wxacode/WxXcxWxaCodeCreateQrCodeReq.java
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
wxacode
;
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
wxacode
;
import
java.io.Serializable
;
/**
/**
* 获取小程序二维码 请求
* 获取小程序二维码 请求
* 适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制
* 适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制
*
*
* @author 李贤军
* @author 李贤军
*/
*/
public
class
WxXcxWxaCodeCreateQrCodeReq
{
public
class
WxXcxWxaCodeCreateQrCodeReq
implements
Serializable
{
/**
/**
* 接口调用凭证
* 接口调用凭证
*/
*/
...
...
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/wxacode/WxXcxWxaCodeCreateQrCodeRequest.java
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
wxacode
;
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
wxacode
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.TypeReference
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
...
@@ -38,7 +39,7 @@ public class WxXcxWxaCodeCreateQrCodeRequest implements WxXcxRequestUrl, WxXcxRe
...
@@ -38,7 +39,7 @@ public class WxXcxWxaCodeCreateQrCodeRequest implements WxXcxRequestUrl, WxXcxRe
@Override
@Override
public
String
getPost
()
{
public
String
getPost
()
{
return
HttpHelper
.
getUrlParameter
(
req
);
return
JSONObject
.
toJSONString
(
req
);
}
}
public
WxXcxWxaCodeCreateQrCodeRes
getResponse
()
{
public
WxXcxWxaCodeCreateQrCodeRes
getResponse
()
{
...
...
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/wxacode/WxXcxWxaCodeGetUnlimitedReq.java
View file @
d066ae4f
...
@@ -7,10 +7,7 @@ package com.yanzuoguang.wxxcx.codeorlink.wxacode;
...
@@ -7,10 +7,7 @@ package com.yanzuoguang.wxxcx.codeorlink.wxacode;
* @author 李贤军
* @author 李贤军
*/
*/
public
class
WxXcxWxaCodeGetUnlimitedReq
{
public
class
WxXcxWxaCodeGetUnlimitedReq
{
/**
* 接口调用凭证
*/
private
String
access_token
;
/**
/**
* 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式
* 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式
*/
*/
...
@@ -27,10 +24,6 @@ public class WxXcxWxaCodeGetUnlimitedReq {
...
@@ -27,10 +24,6 @@ public class WxXcxWxaCodeGetUnlimitedReq {
* 要打开的小程序版本。正式版为 release,体验版为 trial,开发版为 develop
* 要打开的小程序版本。正式版为 release,体验版为 trial,开发版为 develop
*/
*/
private
String
env_version
;
private
String
env_version
;
/**
* 二维码的宽度,单位 px,最小 280px,最大 1280px
*/
private
int
width
;
/**
/**
* 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false
* 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false
*/
*/
...
@@ -44,14 +37,6 @@ public class WxXcxWxaCodeGetUnlimitedReq {
...
@@ -44,14 +37,6 @@ public class WxXcxWxaCodeGetUnlimitedReq {
*/
*/
private
boolean
is_hyaline
;
private
boolean
is_hyaline
;
public
String
getAccess_token
()
{
return
access_token
;
}
public
void
setAccess_token
(
String
access_token
)
{
this
.
access_token
=
access_token
;
}
public
String
getScene
()
{
public
String
getScene
()
{
return
scene
;
return
scene
;
}
}
...
@@ -84,14 +69,6 @@ public class WxXcxWxaCodeGetUnlimitedReq {
...
@@ -84,14 +69,6 @@ public class WxXcxWxaCodeGetUnlimitedReq {
this
.
env_version
=
env_version
;
this
.
env_version
=
env_version
;
}
}
public
int
getWidth
()
{
return
width
;
}
public
void
setWidth
(
int
width
)
{
this
.
width
=
width
;
}
public
boolean
isAuto_color
()
{
public
boolean
isAuto_color
()
{
return
auto_color
;
return
auto_color
;
}
}
...
...
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/wxacode/WxXcxWxaCodeGetUnlimitedRequest.java
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
wxacode
;
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
wxacode
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.TypeReference
;
import
com.sun.org.apache.regexp.internal.RE
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
...
@@ -12,16 +14,16 @@ import com.yanzuoguang.wxxcx.base.*;
...
@@ -12,16 +14,16 @@ import com.yanzuoguang.wxxcx.base.*;
*
*
* @author 李贤军
* @author 李贤军
*/
*/
public
class
WxXcxWxaCodeGetUnlimitedRequest
implements
WxXcxRequestUrl
,
WxXcxRequestUrlPara
,
WxXcxRequestPost
FormData
{
public
class
WxXcxWxaCodeGetUnlimitedRequest
implements
WxXcxRequestUrl
,
WxXcxRequestUrlPara
,
WxXcxRequestPost
Application
{
private
final
WxXcxConfig
wxXcxConfig
;
private
final
WxXcxConfig
wxXcxConfig
;
private
final
WxXcx
Request
wxXcx
Request
;
private
final
WxXcx
ByteArrayRequest
wxXcxByteArray
Request
;
private
final
WxXcxAccessToken
accessToken
;
private
final
WxXcxAccessToken
accessToken
;
private
final
WxXcxWxaCodeGetUnlimitedReq
req
;
private
final
WxXcxWxaCodeGetUnlimitedReq
req
;
public
WxXcxWxaCodeGetUnlimitedRequest
(
WxXcxConfig
wxXcxConfig
,
WxXcx
Request
wxXcx
Request
,
WxXcxAccessToken
accessToken
,
WxXcxWxaCodeGetUnlimitedReq
req
)
{
public
WxXcxWxaCodeGetUnlimitedRequest
(
WxXcxConfig
wxXcxConfig
,
WxXcx
ByteArrayRequest
wxXcxByteArray
Request
,
WxXcxAccessToken
accessToken
,
WxXcxWxaCodeGetUnlimitedReq
req
)
{
this
.
wxXcxConfig
=
wxXcxConfig
;
this
.
wxXcxConfig
=
wxXcxConfig
;
this
.
wxXcx
Request
=
wxXcx
Request
;
this
.
wxXcx
ByteArrayRequest
=
wxXcxByteArray
Request
;
this
.
accessToken
=
accessToken
;
this
.
accessToken
=
accessToken
;
this
.
req
=
req
;
this
.
req
=
req
;
}
}
...
@@ -38,22 +40,21 @@ public class WxXcxWxaCodeGetUnlimitedRequest implements WxXcxRequestUrl, WxXcxRe
...
@@ -38,22 +40,21 @@ public class WxXcxWxaCodeGetUnlimitedRequest implements WxXcxRequestUrl, WxXcxRe
@Override
@Override
public
String
getPost
()
{
public
String
getPost
()
{
return
HttpHelper
.
getUrlParameter
(
req
);
return
JSON
.
toJSONString
(
req
);
}
}
public
WxXcxWxaCodeGetUnlimitedRes
getResponse
()
{
public
WxXcxWxaCodeGetUnlimitedRes
getResponse
()
{
checkParam
(
req
);
checkParam
(
req
);
return
this
.
wxXcxRequest
.
request
(
this
,
response
->
{
return
this
.
wxXcx
ByteArray
Request
.
request
(
this
,
response
->
{
WxXcxWxaCodeGetUnlimitedRes
ret
=
JsonHelper
.
deserialize
(
response
,
new
TypeReference
<
WxXcxWxaCodeGetUnlimitedRes
>()
{
WxXcxWxaCodeGetUnlimitedRes
ret
=
new
WxXcxWxaCodeGetUnlimitedRes
();
}
);
ret
.
setData
(
response
);
WxXcxAssert
.
assertBaseError
(
ret
);
WxXcxAssert
.
assertBaseError
(
ret
);
return
ret
;
return
ret
;
});
});
}
}
private
void
checkParam
(
WxXcxWxaCodeGetUnlimitedReq
req
)
{
private
void
checkParam
(
WxXcxWxaCodeGetUnlimitedReq
req
)
{
CheckerHelper
.
newInstance
().
notBlankCheck
(
WxXcxAccessTokenField
.
FIELD_ACCESS_TOKEN
,
req
.
getAccess_token
())
CheckerHelper
.
newInstance
().
notBlankCheck
(
"scene"
,
req
.
getScene
())
.
notBlankCheck
(
"scene"
,
req
.
getScene
())
.
checkException
();
.
checkException
();
}
}
}
}
\ No newline at end of file
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/wxacode/WxXcxWxaCodeGetUnlimitedRes.java
View file @
d066ae4f
...
@@ -2,8 +2,6 @@ package com.yanzuoguang.wxxcx.codeorlink.wxacode;
...
@@ -2,8 +2,6 @@ package com.yanzuoguang.wxxcx.codeorlink.wxacode;
import
com.yanzuoguang.wxxcx.base.WxXcxResponseBaseError
;
import
com.yanzuoguang.wxxcx.base.WxXcxResponseBaseError
;
import
java.nio.Buffer
;
/**
/**
* 获取小程序码 响应
* 获取小程序码 响应
* 适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制
* 适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制
...
@@ -11,28 +9,13 @@ import java.nio.Buffer;
...
@@ -11,28 +9,13 @@ import java.nio.Buffer;
* @author 李贤军
* @author 李贤军
*/
*/
public
class
WxXcxWxaCodeGetUnlimitedRes
extends
WxXcxResponseBaseError
{
public
class
WxXcxWxaCodeGetUnlimitedRes
extends
WxXcxResponseBaseError
{
/**
private
byte
[]
data
;
* 数据类型 (MIME Type)
*/
private
String
contentType
;
/**
* 数据 Buffer
*/
private
Buffer
buffer
;
public
String
getContentType
()
{
return
contentType
;
}
public
void
setContentType
(
String
contentType
)
{
this
.
contentType
=
contentType
;
}
public
Buffer
getBuffer
()
{
public
byte
[]
getData
()
{
return
buffer
;
return
data
;
}
}
public
void
set
Buffer
(
Buffer
buffer
)
{
public
void
set
Data
(
byte
[]
data
)
{
this
.
buffer
=
buffer
;
this
.
data
=
data
;
}
}
}
}
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/codeorlink/wxacode/service/impl/WxXcxWxaCodeGetUnlimitedServiceImpl.java
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
wxacode
.
service
.
impl
;
package
com
.
yanzuoguang
.
wxxcx
.
codeorlink
.
wxacode
.
service
.
impl
;
import
com.yanzuoguang.wxxcx.base.WxXcxAccessToken
;
import
com.yanzuoguang.wxxcx.base.WxXcxAccessToken
;
import
com.yanzuoguang.wxxcx.base.WxXcxByteArrayRequest
;
import
com.yanzuoguang.wxxcx.base.WxXcxConfig
;
import
com.yanzuoguang.wxxcx.base.WxXcxConfig
;
import
com.yanzuoguang.wxxcx.base.WxXcxRequest
;
import
com.yanzuoguang.wxxcx.base.WxXcxRequest
;
import
com.yanzuoguang.wxxcx.codeorlink.wxacode.WxXcxWxaCodeGetUnlimitedReq
;
import
com.yanzuoguang.wxxcx.codeorlink.wxacode.WxXcxWxaCodeGetUnlimitedReq
;
...
@@ -17,11 +18,11 @@ import org.springframework.stereotype.Component;
...
@@ -17,11 +18,11 @@ import org.springframework.stereotype.Component;
@Component
@Component
public
class
WxXcxWxaCodeGetUnlimitedServiceImpl
implements
WxXcxWxaCodeGetUnlimitedService
{
public
class
WxXcxWxaCodeGetUnlimitedServiceImpl
implements
WxXcxWxaCodeGetUnlimitedService
{
private
final
WxXcxConfig
wxXcxConfig
;
private
final
WxXcxConfig
wxXcxConfig
;
private
final
WxXcx
Request
wxXcx
Request
;
private
final
WxXcx
ByteArrayRequest
wxXcxByteArray
Request
;
public
WxXcxWxaCodeGetUnlimitedServiceImpl
(
WxXcxConfig
wxXcxConfig
,
WxXcx
Request
wxXcx
Request
)
{
public
WxXcxWxaCodeGetUnlimitedServiceImpl
(
WxXcxConfig
wxXcxConfig
,
WxXcx
ByteArrayRequest
wxXcxByteArray
Request
)
{
this
.
wxXcxConfig
=
wxXcxConfig
;
this
.
wxXcxConfig
=
wxXcxConfig
;
this
.
wxXcx
Request
=
wxXcx
Request
;
this
.
wxXcx
ByteArrayRequest
=
wxXcxByteArray
Request
;
}
}
/**
/**
...
@@ -33,7 +34,7 @@ public class WxXcxWxaCodeGetUnlimitedServiceImpl implements WxXcxWxaCodeGetUnlim
...
@@ -33,7 +34,7 @@ public class WxXcxWxaCodeGetUnlimitedServiceImpl implements WxXcxWxaCodeGetUnlim
*/
*/
@Override
@Override
public
WxXcxWxaCodeGetUnlimitedRes
getWxaCodeGetUnlimited
(
WxXcxAccessToken
accessToken
,
WxXcxWxaCodeGetUnlimitedReq
req
)
{
public
WxXcxWxaCodeGetUnlimitedRes
getWxaCodeGetUnlimited
(
WxXcxAccessToken
accessToken
,
WxXcxWxaCodeGetUnlimitedReq
req
)
{
WxXcxWxaCodeGetUnlimitedRequest
request
=
new
WxXcxWxaCodeGetUnlimitedRequest
(
wxXcxConfig
,
wxXcxRequest
,
accessToken
,
req
);
WxXcxWxaCodeGetUnlimitedRequest
request
=
new
WxXcxWxaCodeGetUnlimitedRequest
(
wxXcxConfig
,
wxXcx
ByteArray
Request
,
accessToken
,
req
);
return
request
.
getResponse
();
return
request
.
getResponse
();
}
}
}
}
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/login/service/WxXcxAuthCode2SessionService.java
View file @
d066ae4f
...
@@ -2,7 +2,6 @@ package com.yanzuoguang.wxxcx.login.service;
...
@@ -2,7 +2,6 @@ package com.yanzuoguang.wxxcx.login.service;
import
com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionReq
;
import
com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionReq
;
import
com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionRes
;
import
com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionRes
;
import
com.yanzuoguang.wxxcx.base.WxXcxAccessToken
;
/**
/**
* 登录凭证校验参数 接口
* 登录凭证校验参数 接口
...
@@ -13,10 +12,9 @@ public interface WxXcxAuthCode2SessionService {
...
@@ -13,10 +12,9 @@ public interface WxXcxAuthCode2SessionService {
/**
/**
* 登录凭证校验参数
* 登录凭证校验参数
*
*
* @param accessToken accessToken
* @param req 登录凭证校验参数 入参
* @param req 登录凭证校验参数 入参
* @return 登录凭证校验参数 返回
* @return 登录凭证校验参数 返回
*/
*/
WxXcxAuthCode2SessionRes
getAuthCode2Session
(
WxXcxA
ccessToken
accessToken
,
WxXcxA
uthCode2SessionReq
req
);
WxXcxAuthCode2SessionRes
getAuthCode2Session
(
WxXcxAuthCode2SessionReq
req
);
}
}
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/login/service/impl/WxXcxAuthCode2SessionServiceImpl.java
View file @
d066ae4f
...
@@ -4,7 +4,6 @@ import com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionReq;
...
@@ -4,7 +4,6 @@ import com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionReq;
import
com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionRequest
;
import
com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionRequest
;
import
com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionRes
;
import
com.yanzuoguang.wxxcx.login.WxXcxAuthCode2SessionRes
;
import
com.yanzuoguang.wxxcx.login.service.WxXcxAuthCode2SessionService
;
import
com.yanzuoguang.wxxcx.login.service.WxXcxAuthCode2SessionService
;
import
com.yanzuoguang.wxxcx.base.WxXcxAccessToken
;
import
com.yanzuoguang.wxxcx.base.WxXcxConfig
;
import
com.yanzuoguang.wxxcx.base.WxXcxConfig
;
import
com.yanzuoguang.wxxcx.base.WxXcxRequest
;
import
com.yanzuoguang.wxxcx.base.WxXcxRequest
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -27,12 +26,11 @@ public class WxXcxAuthCode2SessionServiceImpl implements WxXcxAuthCode2SessionSe
...
@@ -27,12 +26,11 @@ public class WxXcxAuthCode2SessionServiceImpl implements WxXcxAuthCode2SessionSe
/**
/**
* 登录凭证校验参数
* 登录凭证校验参数
*
*
* @param accessToken accessToken
* @param req 登录凭证校验参数 入参
* @param req 登录凭证校验参数 入参
* @return 登录凭证校验参数返回
* @return 登录凭证校验参数返回
*/
*/
@Override
@Override
public
WxXcxAuthCode2SessionRes
getAuthCode2Session
(
WxXcxAccessToken
accessToken
,
WxXcxAuthCode2SessionReq
req
)
{
public
WxXcxAuthCode2SessionRes
getAuthCode2Session
(
WxXcxAuthCode2SessionReq
req
)
{
WxXcxAuthCode2SessionRequest
request
=
new
WxXcxAuthCode2SessionRequest
(
wxXcxConfig
,
wxXcxRequest
,
req
);
WxXcxAuthCode2SessionRequest
request
=
new
WxXcxAuthCode2SessionRequest
(
wxXcxConfig
,
wxXcxRequest
,
req
);
return
request
.
getResponse
();
return
request
.
getResponse
();
}
}
...
...
yzg-util-wxxcx/src/main/java/com/yanzuoguang/wxxcx/utils/WeChatUtil.java
0 → 100644
View file @
d066ae4f
package
com
.
yanzuoguang
.
wxxcx
.
utils
;
import
org.bouncycastle.jce.provider.BouncyCastleProvider
;
import
org.bouncycastle.util.Arrays
;
import
org.bouncycastle.util.encoders.Base64
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.security.Key
;
import
java.security.Security
;
/**
* 微信工具类
*
* @author 李贤军
*/
public
class
WeChatUtil
{
public
static
void
main
(
String
[]
args
)
{
String
result
=
decryptData
(
"+6fr9M+bNeRk8LQOOuxqBLuzsydnIh7D2UvImuWicfzJsbrRFptPr7yXHubgTdRd6JHwvjDXD+Q9L0oeTjXlBZilfipjRZJSV7nOpaq++DB5wQr6hKAPsvLmUjOpTPocpVrRDbkXRQKAgl6uTXkR8SdUL3j0zihANr3ANaz2kgg8X+iCJKSxmCuxwPswFCrYaXih2Z7+s/EqWU0ACFgaoZMNkliYBy9mF/pwzCfzsDVx+eJu1eG2UmU6e0e8rUOcEGv4KxfYntvLBN7LJEfOEfYcyemNYtVt3ALDE2sOxI4pb8XxUUO3zn+Yt7e5xWqmfqFj1YK3CCl0ILHle5JlZxGz178PsztDoCnOMoA4NwEoGfqCsUH1pM7AsyfcOh27yqqk="
,
"2gCRTCyEpjQTW5Fc89yg=="
,
"XBzf8VMLBIsFBZvjOWNg=="
);
System
.
out
.
println
(
"result = "
+
result
);
}
public
static
String
decryptData
(
String
encryptDataB64
,
String
sessionKeyB64
,
String
ivB64
)
{
return
new
String
(
decryptOfDiyIV
(
Base64
.
decode
(
encryptDataB64
),
Base64
.
decode
(
sessionKeyB64
),
Base64
.
decode
(
ivB64
)
)
);
}
private
static
final
String
KEY_ALGORITHM
=
"AES"
;
private
static
final
String
ALGORITHM_STR
=
"AES/CBC/PKCS7Padding"
;
private
static
Key
key
;
private
static
Cipher
cipher
;
private
static
void
init
(
byte
[]
keyBytes
)
{
// 如果密钥不足16位,那么就补足. 这个if 中的内容很重要
int
base
=
16
;
if
(
keyBytes
.
length
%
base
!=
0
)
{
int
groups
=
keyBytes
.
length
/
base
+
(
keyBytes
.
length
%
base
!=
0
?
1
:
0
);
byte
[]
temp
=
new
byte
[
groups
*
base
];
Arrays
.
fill
(
temp
,
(
byte
)
0
);
System
.
arraycopy
(
keyBytes
,
0
,
temp
,
0
,
keyBytes
.
length
);
keyBytes
=
temp
;
}
// 初始化
Security
.
addProvider
(
new
BouncyCastleProvider
());
// 转化成JAVA的密钥格式
key
=
new
SecretKeySpec
(
keyBytes
,
KEY_ALGORITHM
);
try
{
// 初始化cipher
cipher
=
Cipher
.
getInstance
(
ALGORITHM_STR
,
"BC"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 解密方法
*
* @param encryptedData 要解密的字符串
* @param keyBytes 解密密钥
* @param ivs 自定义对称解密算法初始向量 iv
* @return 解密后的字节数组
*/
private
static
byte
[]
decryptOfDiyIV
(
byte
[]
encryptedData
,
byte
[]
keyBytes
,
byte
[]
ivs
)
{
byte
[]
encryptedText
=
null
;
init
(
keyBytes
);
try
{
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
key
,
new
IvParameterSpec
(
ivs
));
encryptedText
=
cipher
.
doFinal
(
encryptedData
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
encryptedText
;
}
}
\ No newline at end of file
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