Toggle navigation
Toggle navigation
This project
Loading...
Sign in
jiujian
/
client-customer-order-api
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
zhuyifan
2025-02-19 17:17:26 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
da647259a40488e44b05ef661f01b7a34b805838
da647259
1 parent
c6d6daa0
refactor(config): 重构配置管理并优化相关服务
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
35 deletions
src/main/java/com/infoloop/tianting/config/BusinessConfig.java
src/main/java/com/infoloop/tianting/service/client/ClientCustomerServiceHttpClient.java
src/main/java/com/infoloop/tianting/service/client/PayServiceClient.java
src/main/java/com/infoloop/tianting/service/client/WxMiniProgramClient.java
src/main/resources/application.properties
src/main/java/com/infoloop/tianting/config/BusinessConfig.java
0 → 100644
View file @
da64725
package
com
.
infoloop
.
tianting
.
config
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.stereotype.Component
;
@Component
@ConfigurationProperties
(
prefix
=
"business-config"
)
@Data
@PropertySource
(
encoding
=
"UTF-8"
,
value
=
"classpath:application.properties"
,
ignoreResourceNotFound
=
true
)
public
class
BusinessConfig
{
private
String
hisCustomerQueryUrl
;
private
String
clientCustomerQueryUrl
;
private
String
payUrl
;
}
src/main/java/com/infoloop/tianting/service/client/ClientCustomerServiceHttpClient.java
View file @
da64725
...
...
@@ -2,6 +2,7 @@ package com.infoloop.tianting.service.client;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.infoloop.tianting.config.BusinessConfig
;
import
com.infoloop.tianting.model.dto.ClientCustomerDbDTO.CurrentClientCustomerDto
;
import
com.infoloop.tianting.model.dto.ClientCustomerDbDTO.CurrentClientCustomerListDto
;
import
lombok.RequiredArgsConstructor
;
...
...
@@ -18,18 +19,20 @@ import java.util.List;
@Service
@RequiredArgsConstructor
(
onConstructor
=
@__
(
@Autowired
))
public
class
ClientCustomerServiceHttpClient
{
private
final
BusinessConfig
businessConfig
;
private
final
OkHttpClient
client
=
new
OkHttpClient
();
public
List
<
CurrentClientCustomerDto
>
getCurrentClientCustomer
(
String
token
,
boolean
isHis
)
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
String
url
=
""
;
String
url
;
if
(
isHis
)
{
url
=
"https://nutri.amcare.com.cn/v3/hiscustomers/current/query"
;
url
=
businessConfig
.
getHisCustomerQueryUrl
()
;
}
else
{
url
=
"https://nutri.amcare.com.cn/v3/clientcustomers/current/query"
;
url
=
businessConfig
.
getClientCustomerQueryUrl
()
;
}
MediaType
mediaType
=
MediaType
.
parse
(
"application/json; charset=utf-8"
);
RequestBody
body
=
RequestBody
.
create
(
mediaType
,
"{}"
);
Request
request
=
new
Request
.
Builder
()
...
...
src/main/java/com/infoloop/tianting/service/client/PayServiceClient.java
View file @
da64725
package
com
.
infoloop
.
tianting
.
service
.
client
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonParser.Feature
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.MapperFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.PropertyNamingStrategy
;
import
com.
fasterxml.jackson.databind.SerializationFeature
;
import
com.
infoloop.tianting.config.BusinessConfig
;
import
com.infoloop.tianting.model.dto.PayDTO.PayInformRequestDto
;
import
com.infoloop.tianting.model.dto.PayDTO.PayResponseDto
;
import
com.infoloop.tianting.model.dto.PayDTO.ThirdPartyPayInformRequestDto
;
import
com.infoloop.tianting.model.dto.WxUserDto.WxUserPhoneResponseDto
;
import
com.infoloop.tianting.utils.DateUtil
;
import
com.infoloop.tianting.utils.EncryptionUtil
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
lombok.RequiredArgsConstructor
;
import
okhttp3.FormBody
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy
;
import
org.springframework.jmx.export.naming.IdentityNamingStrategy
;
import
org.springframework.stereotype.Service
;
import
java.time.LocalDateTime
;
@Service
@RequiredArgsConstructor
(
onConstructor
=
@__
(
@Autowired
))
public
class
PayServiceClient
{
private
final
OkHttpClient
client
=
new
OkHttpClient
();
private
final
BusinessConfig
businessConfig
;
public
PayResponseDto
payInform
(
PayInformRequestDto
payRequestDto
)
{
try
{
String
url
=
"http://10.2.5.162:21051/API/Microapp/CreateOrder?appid=Order0001"
;
String
url
=
businessConfig
.
getPayUrl
()
;
String
clientId
=
"Order0001"
;
ObjectMapper
objectMapper
=
new
ObjectMapper
();
// objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
...
...
@@ -53,11 +50,9 @@ public class PayServiceClient {
jsonData
.
setRemark
(
""
);
jsonData
.
setTransAmount
(
payRequestDto
.
getPrice
());
jsonData
.
setTradeDesc
(
""
);
String
signStr
=
EncryptionUtil
.
sha1Encryption
(
clientId
+
payRequestDto
.
getOrderId
()+
requestDate
+
"Order0001"
);
String
signStr
=
EncryptionUtil
.
sha1Encryption
(
clientId
+
payRequestDto
.
getOrderId
()
+
requestDate
+
"Order0001"
);
jsonData
.
setSign
(
signStr
);
String
jsonDataString
=
objectMapper
.
writeValueAsString
(
jsonData
);
// 设置请求体的媒体类型为JSON
MediaType
mediaType
=
MediaType
.
parse
(
"application/json; charset=utf-8"
);
RequestBody
body
=
RequestBody
.
create
(
mediaType
,
jsonDataString
);
...
...
@@ -66,19 +61,17 @@ public class PayServiceClient {
.
post
(
body
)
.
build
();
Response
payResponse
=
client
.
newCall
(
getPhoneRequest
).
execute
();
if
(
payResponse
.
code
()
!=
200
)
{
if
(
payResponse
.
code
()
!=
200
)
{
System
.
out
.
println
(
payResponse
.
message
());
throw
new
IllegalArgumentException
(
"支付通知失败"
);
}
String
payJsonData
=
payResponse
.
body
().
string
();
System
.
out
.
println
(
"pay json:"
+
payJsonData
);
System
.
out
.
println
(
"pay json:"
+
payJsonData
);
ObjectMapper
objectMapper2
=
new
ObjectMapper
();
objectMapper2
.
configure
(
Feature
.
ALLOW_MISSING_VALUES
,
true
);
objectMapper2
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
objectMapper2
.
configure
(
MapperFeature
.
ACCEPT_CASE_INSENSITIVE_VALUES
,
false
);
PayResponseDto
payResponseDto
=
objectMapper2
.
readValue
(
payJsonData
,
PayResponseDto
.
class
);
return
payResponseDto
;
return
objectMapper2
.
readValue
(
payJsonData
,
PayResponseDto
.
class
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getStackTrace
().
toString
());
throw
new
IllegalArgumentException
(
"支付通知失败"
);
...
...
src/main/java/com/infoloop/tianting/service/client/WxMiniProgramClient.java
View file @
da64725
...
...
@@ -2,36 +2,39 @@ package com.infoloop.tianting.service.client;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.infoloop.tianting.constant.ConfigConstants
;
import
com.infoloop.tianting.model.dto.WxUserDto
;
import
com.infoloop.tianting.model.dto.WxUserDto.WxUserCodeDto
;
import
com.infoloop.tianting.model.dto.WxUserDto.WxUserOpenIdDto
;
import
com.infoloop.tianting.model.dto.WxUserDto.WxUserOpenIdDto1
;
import
com.infoloop.tianting.model.dto.WxUserDto.WxUserPhoneResponseDto
;
import
com.infoloop.tianting.model.dto.WxUserDto.WxUserTokenDto
;
import
com.infoloop.tianting.utils.JsonUtil
;
import
lombok.RequiredArgsConstructor
;
import
lombok.Value
;
import
okhttp3.FormBody
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.b
oot.context.properties.source.ConfigurationPropertyName.Form
;
import
org.springframework.b
eans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
static
com
.
infoloop
.
tianting
.
constant
.
ConfigConstants
.
MINI_PROGRAM_APP_ID
;
import
static
com
.
infoloop
.
tianting
.
constant
.
ConfigConstants
.
MINI_PROGRAM_APP_SECRET
;
@Service
@RequiredArgsConstructor
(
onConstructor
=
@__
(
@Autowired
))
public
class
WxMiniProgramClient
{
@Value
(
MINI_PROGRAM_APP_ID
)
private
String
appId
;
@Value
(
MINI_PROGRAM_APP_SECRET
)
private
String
appSecret
;
private
final
OkHttpClient
client
=
new
OkHttpClient
();
public
WxUserPhoneResponseDto
getUserPhoneInfoByCode
(
String
code
)
{
try
{
String
getTokenUrl
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=
wx40ec496d73b58ec6"
+
"&secret=
5b309517bf918abf760b2195e91b99f3"
;
String
getTokenUrl
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=
"
+
appId
+
"&secret=
"
+
appSecret
;
Request
getTokenRequest
=
new
Request
.
Builder
()
.
url
(
getTokenUrl
)
.
build
();
...
...
@@ -40,7 +43,6 @@ public class WxMiniProgramClient {
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
String
tokenJsonData
=
getTokenResponse
.
body
().
string
();
WxUserTokenDto
wxUserTokenDto
=
objectMapper
.
readValue
(
tokenJsonData
,
WxUserTokenDto
.
class
);
System
.
out
.
println
(
"token:"
+
wxUserTokenDto
.
getAccess_token
());
String
getPhoneUrl
=
"https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="
+
wxUserTokenDto
.
getAccess_token
();
WxUserCodeDto
jsonData
=
new
WxUserCodeDto
();
...
...
@@ -56,7 +58,6 @@ public class WxMiniProgramClient {
String
phoneJsonData
=
getPhoneResponse
.
body
().
string
();
WxUserPhoneResponseDto
wxUserPhoneResponseDto
=
objectMapper
.
readValue
(
phoneJsonData
,
WxUserPhoneResponseDto
.
class
);
return
wxUserPhoneResponseDto
;
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
throw
new
IllegalArgumentException
(
"获取用户手机号失败"
);
...
...
@@ -67,14 +68,12 @@ public class WxMiniProgramClient {
try
{
String
url
=
"https://api.weixin.qq.com/sns/jscode2session"
+
"?appid=
wx40ec496d73b58ec6"
+
"&secret=5b309517bf918abf760b2195e91b99f3"
+
"&js_code="
+
code
+
"&grant_type=authorization_code"
;
"?appid=
"
+
appId
+
"&secret="
+
appSecret
+
"&js_code="
+
code
+
"&grant_type=authorization_code"
;
System
.
out
.
println
(
"url:"
+
url
);
Request
request
=
new
Request
.
Builder
()
.
url
(
url
)
.
build
();
Response
response
=
client
.
newCall
(
request
).
execute
();
String
jsonData
=
response
.
body
().
string
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
...
...
src/main/resources/application.properties
View file @
da64725
...
...
@@ -76,6 +76,10 @@ grpc.meizhongyihe-service.port=3040
miniprogram.appId
=
wx40ec496d73b58ec6
miniprogram.appSecret
=
5b309517bf918abf760b2195e91b99f3
business-
config.hisCustomerQueryUrl
=
https://nutri.amcare.com.cn/v3/hiscustomers/current/query
business-
config.clientCustomerQueryUrl
=
https://nutri.amcare.com.cn/v3/clientcustomers/current/query
business-
config.payUrl
=
http://10.2.5.162:21051/API/Microapp/CreateOrder?appid=Order0001
##Actuator\u914D\u7F6E
management.server.port
=
8088
management.endpoints.web.exposure.include
=
*
...
...
Please
register
or
login
to post a comment