Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gdtel-gztel-school-center
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴学德
gdtel-gztel-school-center
Commits
4b47d9e6
Commit
4b47d9e6
authored
May 30, 2020
by
彭祥礼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信支付调整
parent
20dd9273
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
52 deletions
+52
-52
apply-net/src/main/java/com/winsun/controller/YxtCardController.java
+14
-6
common/src/main/java/com/winsun/utils/HTTPSClient.java
+24
-26
common/src/main/java/com/winsun/utils/WxConfig.java
+2
-2
common/src/main/java/com/winsun/utils/WxInterfacesUtil.java
+12
-18
No files found.
apply-net/src/main/java/com/winsun/controller/YxtCardController.java
View file @
4b47d9e6
...
...
@@ -102,10 +102,15 @@ public class YxtCardController extends BaseController {
public
ResponseData
<
Map
<
String
,
Object
>>
enterPay
(
String
code
)
throws
Exception
{
Map
<
String
,
Object
>
objectMap
=
new
HashMap
<>();
String
openIdt
=
""
;
String
result
=
WxInterfacesUtil
.
getAccess_tokenByCode
(
code
);
String
openIdt
=
redisTemplate
.
opsForValue
().
get
(
"openid"
).
toString
();
Object
object
=
redisTemplate
.
opsForValue
().
get
(
"openid"
);
if
(
object
!=
null
){
openIdt
=
object
.
toString
();
}
if
(
StringUtils
.
isNotBlank
(
result
))
{
JSONObject
obj
=
JSONObject
.
fromObject
(
result
);
redisTemplate
.
opsForValue
().
set
(
"access_token"
,
obj
.
get
(
"access_token"
),
120
,
TimeUnit
.
MINUTES
);
String
openId
=
String
.
valueOf
(
obj
.
get
(
"openid"
));
// code重复使用时,从session拿出第一次保存openId赋予openId
if
(
"null"
.
equals
(
openId
)
&&
!
"null"
.
equals
(
openIdt
)){
...
...
@@ -134,9 +139,14 @@ public class YxtCardController extends BaseController {
public
ResponseData
<
Map
<
String
,
Object
>>
getJsapiSign
(
HttpServletRequest
request
){
// 加密参数
String
url
=
"http://"
+
request
.
getServerName
()+
request
.
getRequestURI
();
String
access_token
=
""
;
Object
obj
=
redisTemplate
.
opsForValue
().
get
(
"access_token"
);
Map
<
String
,
Object
>
objectMap
=
null
;
try
{
objectMap
=
new
WxInterfacesUtil
().
getJspaiSign
(
url
);
if
(
obj
!=
null
){
access_token
=
obj
.
toString
();
}
objectMap
=
new
WxInterfacesUtil
().
getJspaiSign
(
url
,
access_token
);
objectMap
.
put
(
"appid"
,
WxConfig
.
APPID
);
return
ResponseData
.
success
(
objectMap
);
}
catch
(
Exception
e
){
...
...
@@ -293,11 +303,9 @@ public class YxtCardController extends BaseController {
payRequest
.
setSpbill_create_ip
(
"120.24.88.216"
);
payRequest
.
setNotify_url
(
WxConfig
.
NOTIFY_URL
);
payRequest
.
setTrade_type
(
"JSAPI"
);
//临时测试用
payRequest
.
setOpenid
(
"o22lhwRZP2zbXff7UHH3J8oqH8A0"
);
//payRequest.setOpenid("o22lhwRZP2zbXff7UHH3J8oqH8A0");//临时测试用
log
.
info
(
"pay——openid:"
+
openId
);
//
payRequest.setOpenid(openId);
payRequest
.
setOpenid
(
openId
);
// 统一下单加密参数
SortedMap
<
Object
,
Object
>
parameters
=
new
TreeMap
<
Object
,
Object
>();
...
...
common/src/main/java/com/winsun/utils/HTTPSClient.java
View file @
4b47d9e6
...
...
@@ -5,7 +5,9 @@ import net.sf.json.JSONArray;
import
net.sf.json.JSONObject
;
import
org.apache.commons.httpclient.HttpClient
;
import
org.apache.commons.httpclient.HttpStatus
;
import
org.apache.commons.httpclient.methods.GetMethod
;
import
org.apache.commons.httpclient.methods.PostMethod
;
import
org.apache.commons.httpclient.params.HttpMethodParams
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpResponse
;
...
...
@@ -283,39 +285,36 @@ public class HTTPSClient {
// 原方法 不走代理
// public static String sendGet(String url) {
// String result = "";
// HttpClient client = new HttpClient();
// GetMethod getMethod = new GetMethod(url);
// getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 25000);
// try {
// int statusCode = client.executeMethod(getMethod);
// if (statusCode == HttpStatus.SC_OK) {
// result = getMethod.getResponseBodyAsString(); // 出现中文乱码
// // result = new String(getMethod.getResponseBody(),"utf-8");
// }
//
// } catch (ClientProtocolException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } catch (IllegalStateException e) {
// e.printStackTrace();
// }
//
// return result;
// }
public
static
String
sendGet
(
String
url
)
{
String
result
=
""
;
HttpClient
client
=
new
HttpClient
();
GetMethod
getMethod
=
new
GetMethod
(
url
);
getMethod
.
getParams
().
setParameter
(
HttpMethodParams
.
SO_TIMEOUT
,
25000
);
try
{
int
statusCode
=
client
.
executeMethod
(
getMethod
);
if
(
statusCode
==
HttpStatus
.
SC_OK
)
{
result
=
getMethod
.
getResponseBodyAsString
();
// 出现中文乱码
// result = new String(getMethod.getResponseBody(),"utf-8");
}
}
catch
(
ClientProtocolException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalStateException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
// 新方法 走代理
public
static
String
sendGet
(
String
url
)
{
public
static
String
sendGet
2
(
String
url
)
{
String
string
=
""
;
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
HttpPost
httpPost
=
new
HttpPost
(
url
);
try
{
HttpHost
proxy
=
new
HttpHost
(
"172.18.101.170"
,
3128
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
200000
).
setConnectTimeout
(
200000
).
setProxy
(
proxy
).
build
();
httpPost
.
setConfig
(
requestConfig
);
CloseableHttpResponse
result
=
httpClient
.
execute
(
httpPost
);
string
=
EntityUtils
.
toString
(
result
.
getEntity
(),
"utf-8"
);
;
...
...
@@ -327,7 +326,6 @@ public class HTTPSClient {
}
catch
(
IllegalStateException
e
)
{
e
.
printStackTrace
();
}
return
string
;
}
...
...
common/src/main/java/com/winsun/utils/WxConfig.java
View file @
4b47d9e6
...
...
@@ -9,7 +9,7 @@ public class WxConfig {
/**************公众号参数信息*************/
// 公众号appid 校园服务号
//
public static final String APPID = "wx0641dc1dc4d34384";
public
static
final
String
APPID
=
"wx0641dc1dc4d34384"
;
// 公众号秘钥 secret 校园服务号
public
static
final
String
APPSECRET
=
"3b43b46fc94d4e98588ee6ad992fa5c7"
;
...
...
@@ -19,7 +19,7 @@ public class WxConfig {
public
static
final
String
NOTIFY_URL
=
"http://dianyuanjiangli.com/xyjl/yx/wxpay/yxt!payNotify.action"
;
// // 公众号appid 网讯测试服务号
public
static
final
String
APPID
=
"wxfc18f5186b729d15"
;
//
public static final String APPID = "wxfc18f5186b729d15";
//
// // 公众号秘钥 secret 网讯测试服务号
// public static final String APPSECRET = "122278f3fb555468848ff040620505ad";
...
...
common/src/main/java/com/winsun/utils/WxInterfacesUtil.java
View file @
4b47d9e6
package
com
.
winsun
.
utils
;
import
net.sf.ehcache.Element
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.ParseException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
...
@@ -15,7 +15,6 @@ import java.security.MessageDigest;
import
java.security.NoSuchAlgorithmException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
public
class
WxInterfacesUtil
{
...
...
@@ -26,27 +25,21 @@ public class WxInterfacesUtil {
/**
* 获取凭证
* @param grant_type 获取access_token填写client_credential
* @param appid 第三方用户唯一凭证
* @par
edisTemplater
am appid 第三方用户唯一凭证
* @param secret 第三方用户唯一凭证密钥,既appsecret
* @return json token:获取到的凭证 expires_in:凭证有效时间,单位:秒
*/
public
String
getToken
(
String
grant_type
,
String
appid
,
String
secret
){
public
String
getToken
(
String
grant_type
,
String
appid
,
String
secret
,
String
access_token
){
String
result
=
null
;
Element
ele
=
null
;
//tokenCache.get("token_cache");
if
(
ele
!=
null
){
result
=
(
String
)
ele
.
getValue
();
if
(
StringUtils
.
isNotBlank
(
access_token
)){
result
=
access_token
;
}
else
{
String
url
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type="
+
grant_type
+
"&appid="
+
appid
+
"&secret="
+
secret
;
String
res
=
HTTPSClient
.
sendGet
(
url
);
JSONObject
jobj
=
JSONObject
.
fromObject
(
res
);
if
(
jobj
.
has
(
"access_token"
)){
result
=
jobj
.
getString
(
"access_token"
);
}
ele
=
new
Element
(
"token_cache"
,
result
);
//两小时内有效
redisTemplate
.
opsForValue
().
set
(
"token_cache"
,
ele
,
120
,
TimeUnit
.
MINUTES
);
//tokenCache.put(ele);
}
return
result
;
...
...
@@ -106,20 +99,21 @@ public class WxInterfacesUtil {
return
result
;
}
public
Map
<
String
,
Object
>
getJspaiSign
(
String
url
)
{
public
Map
<
String
,
Object
>
getJspaiSign
(
String
url
,
String
access_token
)
{
Map
<
String
,
Object
>
jsonObject
=
new
HashMap
<>();
// 时间戳
long
timeStamp
=
System
.
currentTimeMillis
();
// 随机字符串
String
nonceStr
=
Integer
.
toString
(((
int
)
((
Math
.
random
()
+
1
)
*
1000000
)));
// 凭证
String
accessToken
=
getToken
(
"client_credential"
,
WxConfig
.
APPID
,
WxConfig
.
APPSECRET
);
if
(
StringUtils
.
isBlank
(
access_token
)){
access_token
=
getToken
(
"client_credential"
,
WxConfig
.
APPID
,
WxConfig
.
APPSECRET
,
access_token
);
}
jsonObject
.
put
(
"access_token"
,
access_token
);
// 票据
String
ticket
=
getJsapiTicket
(
access
T
oken
);
String
ticket
=
getJsapiTicket
(
access
_t
oken
);
String
signature
=
""
;
String
params
=
"jsapi_ticket="
+
ticket
+
"&noncestr="
+
nonceStr
+
"×tamp="
+
timeStamp
+
"&url="
+
url
;
try
{
// 获取签名
MessageDigest
crypt
=
MessageDigest
.
getInstance
(
"SHA-1"
);
...
...
@@ -470,7 +464,7 @@ public class WxInterfacesUtil {
* @return
*/
public
static
String
getAccess_tokenByCode
(
String
code
){
//https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
String
url
=
"https://api.weixin.qq.com/sns/oauth2/access_token?appid="
+
WxConfig
.
APPID
+
"&secret="
+
WxConfig
.
APPSECRET
+
"&code="
+
code
+
"&grant_type=authorization_code"
;
String
result
=
""
;
result
=
HTTPSClient
.
sendGet
(
url
);
...
...
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