Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
consume
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
竹天卫
consume
Commits
a2e33f19
Commit
a2e33f19
authored
4 years ago
by
shulidong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
百应领取优惠券api
parent
7b5cb5d3
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
251 additions
and
4 deletions
+251
-4
pom.xml
consume-business/pom.xml
+0
-4
BaiyingApi.java
...a/cn/wise/sc/consume/business/api/baiying/BaiyingApi.java
+120
-0
Request.java
...java/cn/wise/sc/consume/business/api/baiying/Request.java
+37
-0
RequestHead.java
.../cn/wise/sc/consume/business/api/baiying/RequestHead.java
+88
-0
package-info.java
...in/java/cn/wise/sc/consume/business/api/package-info.java
+6
-0
No files found.
consume-business/pom.xml
View file @
a2e33f19
...
...
@@ -70,10 +70,6 @@
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpcore
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
...
...
This diff is collapsed.
Click to expand it.
consume-business/src/main/java/cn/wise/sc/consume/business/api/baiying/BaiyingApi.java
0 → 100644
View file @
a2e33f19
package
cn
.
wise
.
sc
.
consume
.
business
.
api
.
baiying
;
import
cn.wise.sc.consume.business.util.HttpClientUtil
;
import
com.alibaba.fastjson.JSON
;
import
org.springframework.util.DigestUtils
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
/**
* @Author: wangc
* @Description:
*/
public
class
BaiyingApi
{
//开发环境配置
private
static
String
openid
=
"19198e6d7feedda5"
;;
private
static
String
cipher
=
"6276bcfcbd71966e"
;;
//服务器地址
private
static
String
url
=
"http://116.62.180.218:8082"
;
public
static
void
main
(
String
[]
args
)
{
// getAccessToken_2_0();
synRedeemCodeState
();
}
private
static
void
synRedeemCodeState
(){
Map
<
String
,
String
>
params
=
new
HashMap
<>();
params
.
put
(
"code"
,
"3243-fd3d-232d-343d"
);
//优惠券兑换码
String
resStr
=
myReqHttp
(
"thirdbuss/synRedeemCodeState.do"
,
params
);
System
.
out
.
println
(
resStr
);
}
private
static
void
getAccessToken_2_0
(){
Map
<
String
,
String
>
body
=
new
HashMap
<>();
body
.
put
(
"scope"
,
"jump_page"
);
String
resStr
=
myReqHttp
(
"auth/getAccessToken.do"
,
body
);
}
private
static
String
myReqHttp
(
String
methodUrl
,
Map
<
String
,
String
>
body
){
Request
request
=
new
Request
();
RequestHead
head
=
new
RequestHead
();
//head.setTime(DateUtils.format(DateUtils.now(),"yyyy-MM-dd HH:mm:ss"));
head
.
setTime
(
LocalDateTime
.
now
().
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
head
.
setOpenid
(
openid
);
head
.
setVersion
(
"2.0"
);
head
.
setFormat
(
"JSON"
);
request
.
setBody
(
body
);
//需对body中的业务参数key进行ascii从小到大排序(字典序) 进行如下拼接
String
body_str
=
getSignValue
(
body
);
String
sign_1
=
"openid="
+
openid
+
"&time="
+
head
.
getTime
()+
"&body={"
+
body_str
+
"}&cipher="
+
cipher
;
System
.
out
.
println
(
"明文:"
+
sign_1
);
head
.
setSign
(
DigestUtils
.
md5DigestAsHex
(
sign_1
.
getBytes
()));
request
.
setHead
(
head
);
String
reqJson
=
JSON
.
toJSONString
(
request
);
System
.
out
.
println
(
"reqJson\n"
+
reqJson
);
String
resStr
=
HttpClientUtil
.
doPostJson
(
url
+
"/"
+
methodUrl
,
reqJson
);
// String resStr = "";
System
.
out
.
println
(
"resStr:\n"
+
resStr
);
return
resStr
;
}
private
static
String
CreateNoncestr
()
{
String
chars
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
String
res
=
""
;
for
(
int
i
=
0
;
i
<
16
;
i
++)
{
Random
rd
=
new
Random
();
res
+=
chars
.
charAt
(
rd
.
nextInt
(
chars
.
length
()
-
1
));
}
return
res
;
}
/**
* 排序后获取需要签名的字符串
* @param map
* @return
*/
public
static
String
getSignValue
(
Map
<
String
,
String
>
map
)
{
String
result
=
""
;
try
{
List
<
Map
.
Entry
<
String
,
String
>>
infoIds
=
new
ArrayList
<
Map
.
Entry
<
String
,
String
>>(
map
.
entrySet
());
// 对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序)
Collections
.
sort
(
infoIds
,
new
Comparator
<
Map
.
Entry
<
String
,
String
>>()
{
public
int
compare
(
Map
.
Entry
<
String
,
String
>
o1
,
Map
.
Entry
<
String
,
String
>
o2
)
{
return
(
o1
.
getKey
()).
toString
().
compareTo
(
o2
.
getKey
());
}
});
// 构造签名键值对的格式
StringBuilder
sb
=
new
StringBuilder
();
for
(
Map
.
Entry
<
String
,
String
>
item
:
infoIds
)
{
if
(
item
.
getKey
()
!=
null
||
item
.
getKey
()
!=
""
)
{
String
key
=
item
.
getKey
();
sb
.
append
(
key
+
"="
+
(
item
.
getValue
()==
null
?
""
:
item
.
getValue
())+
"&"
);
}
}
result
=
sb
.
toString
().
substring
(
0
,
sb
.
toString
().
length
()-
1
);
}
catch
(
Exception
e
)
{
return
null
;
}
return
result
;
}
}
This diff is collapsed.
Click to expand it.
consume-business/src/main/java/cn/wise/sc/consume/business/api/baiying/Request.java
0 → 100644
View file @
a2e33f19
package
cn
.
wise
.
sc
.
consume
.
business
.
api
.
baiying
;
import
java.util.Map
;
/**
* 请求实体
*
*/
public
class
Request
{
/**
* 请求头
*/
private
RequestHead
head
;
/**
* 请求体
*/
private
Map
<
String
,
String
>
body
;
public
RequestHead
getHead
()
{
return
head
;
}
public
void
setHead
(
RequestHead
head
)
{
this
.
head
=
head
;
}
public
Map
<
String
,
String
>
getBody
()
{
return
body
;
}
public
void
setBody
(
Map
<
String
,
String
>
body
)
{
this
.
body
=
body
;
}
}
This diff is collapsed.
Click to expand it.
consume-business/src/main/java/cn/wise/sc/consume/business/api/baiying/RequestHead.java
0 → 100644
View file @
a2e33f19
package
cn
.
wise
.
sc
.
consume
.
business
.
api
.
baiying
;
/**
* 请求头
*
*/
public
class
RequestHead
{
/**
* 百应分配给商户的openid
*/
private
String
openid
;
/**
* 仅支持JSON
*/
private
String
format
=
"JSON"
;
/**
* 签名类型
*/
private
String
sign_type
=
"MD5"
;
/**
* 请求参数的签名串
*/
private
String
sign
;
/**
* 客户端时间,yyyy-MM-dd HH:mm:ss
*/
private
String
time
;
/**
* 调用的接口版本,固定为:1.0
*/
private
String
version
=
"1.0"
;
public
String
getFormat
()
{
return
format
;
}
public
void
setFormat
(
String
format
)
{
this
.
format
=
format
;
}
public
String
getSign_type
()
{
return
sign_type
;
}
public
void
setSign_type
(
String
sign_type
)
{
this
.
sign_type
=
sign_type
;
}
public
String
getSign
()
{
return
sign
;
}
public
void
setSign
(
String
sign
)
{
this
.
sign
=
sign
;
}
public
String
getTime
()
{
return
time
;
}
public
void
setTime
(
String
time
)
{
this
.
time
=
time
;
}
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
public
String
getOpenid
()
{
return
openid
;
}
public
void
setOpenid
(
String
openid
)
{
this
.
openid
=
openid
;
}
}
This diff is collapsed.
Click to expand it.
consume-business/src/main/java/cn/wise/sc/consume/business/api/package-info.java
0 → 100644
View file @
a2e33f19
/**
* @author neo.shu
* @since 2020/10/26 16:42
*/
package
cn
.
wise
.
sc
.
consume
.
business
.
api
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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