Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
23eea9a7
Commit
23eea9a7
authored
Feb 20, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
发送模板消息
parent
c2316d0f
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
478 additions
and
4 deletions
+478
-4
ch-core/src/main/resources/application-dev.yml
ch-core/src/main/resources/application-dev.yml
+10
-1
ch-core/src/main/resources/application-prod.yml
ch-core/src/main/resources/application-prod.yml
+8
-0
ch-dao/src/main/resources/generatorConfig_new.xml
ch-dao/src/main/resources/generatorConfig_new.xml
+1
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/WxPayCallbackController.java
...main/java/com/wwdz/ch/wx/api/WxPayCallbackController.java
+31
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
.../main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
+2
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/DeliveryNoticeMsg.java
...rc/main/java/com/wwdz/ch/wx/entity/DeliveryNoticeMsg.java
+65
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/PayNoticeMsg.java
...api/src/main/java/com/wwdz/ch/wx/entity/PayNoticeMsg.java
+65
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/SignedNoticeMsg.java
.../src/main/java/com/wwdz/ch/wx/entity/SignedNoticeMsg.java
+59
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/DistributionOrderServiceImpl.java
...ch/wx/impl/distribution/DistributionOrderServiceImpl.java
+56
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/SendMsgServiceImpl.java
.../com/wwdz/ch/wx/impl/distribution/SendMsgServiceImpl.java
+163
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/distribution/SendMsgService.java
...a/com/wwdz/ch/wx/service/distribution/SendMsgService.java
+18
-0
No files found.
ch-core/src/main/resources/application-dev.yml
View file @
23eea9a7
...
@@ -17,8 +17,11 @@ dts:
...
@@ -17,8 +17,11 @@ dts:
get-access-token-url
:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s
get-access-token-url
:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s
#公众号消息点击后跳转到小程序页面的链接
#
寄售业务,
公众号消息点击后跳转到小程序页面的链接
msg-url
:
pages/consignNodeDetail/index
msg-url
:
pages/consignNodeDetail/index
#分销业务,公众号消息点击后跳转到小程序页面的链接
distribution-msg-url
:
pages/saleOrderDetail/index
# 商户证书文件路径
# 商户证书文件路径
# 请参考“商户证书”一节 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3
# 请参考“商户证书”一节 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3
key-path
:
xxxxx
key-path
:
xxxxx
...
@@ -29,6 +32,12 @@ dts:
...
@@ -29,6 +32,12 @@ dts:
officialaccount-key
:
noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM
officialaccount-key
:
noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM
get-officialaccount-accesstoken-url
:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s
get-officialaccount-accesstoken-url
:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s
officialaccount-templetId
:
WJkhzyY0_7AYqh19_ujK9yZhj4HohF8ETJvG5NYA9A8
officialaccount-templetId
:
WJkhzyY0_7AYqh19_ujK9yZhj4HohF8ETJvG5NYA9A8
#分销单支付成功通知模板
pay-templetId
:
X38RkH7DtKNDHUMa2P6XXqrEmkHIEvbpTWTr7Mkf2fM
#分销单发货成功通知模板
delivery-templetId
:
8apEOIXxlLHrEQ20a-o_PHXogGtgKHu25zHzFg3RPeI
#分销订单确认收货通知模板
signed-templetId
:
k2dPOA4wvLPGf_4z76sGoA2KXHQWGEWpYT_imXlOpJI
#微信支付配置
#微信支付配置
wx-pay
:
wx-pay
:
...
...
ch-core/src/main/resources/application-prod.yml
View file @
23eea9a7
...
@@ -11,6 +11,8 @@ dts:
...
@@ -11,6 +11,8 @@ dts:
#公众号消息点击后跳转到小程序页面的链接
#公众号消息点击后跳转到小程序页面的链接
msg-url
:
pages/consignNodeDetail/index
msg-url
:
pages/consignNodeDetail/index
#分销业务,公众号消息点击后跳转到小程序页面的链接
distribution-msg-url
:
pages/saleOrderDetail/index
# 商户证书文件路径
# 商户证书文件路径
# 请参考“商户证书”一节 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3
# 请参考“商户证书”一节 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3
key-path
:
xxxxx
key-path
:
xxxxx
...
@@ -21,6 +23,12 @@ dts:
...
@@ -21,6 +23,12 @@ dts:
officialaccount-key
:
noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM
officialaccount-key
:
noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM
get-officialaccount-accesstoken-url
:
https://api.weixin.qq.com/cgi-bin/stable_token
get-officialaccount-accesstoken-url
:
https://api.weixin.qq.com/cgi-bin/stable_token
officialaccount-templetId
:
WJkhzyY0_7AYqh19_ujK9yZhj4HohF8ETJvG5NYA9A8
officialaccount-templetId
:
WJkhzyY0_7AYqh19_ujK9yZhj4HohF8ETJvG5NYA9A8
#分销单支付成功通知模板
pay-templetId
:
X38RkH7DtKNDHUMa2P6XXqrEmkHIEvbpTWTr7Mkf2fM
#分销单发货成功通知模板
delivery-templetId
:
8apEOIXxlLHrEQ20a-o_PHXogGtgKHu25zHzFg3RPeI
#分销订单确认收货通知模板
signed-templetId
:
k2dPOA4wvLPGf_4z76sGoA2KXHQWGEWpYT_imXlOpJI
#微信支付配置
#微信支付配置
wx-pay
:
wx-pay
:
...
...
ch-dao/src/main/resources/generatorConfig_new.xml
View file @
23eea9a7
...
@@ -72,7 +72,7 @@
...
@@ -72,7 +72,7 @@
<javaClientGenerator
type=
"XMLMAPPER"
targetPackage=
"com.wwdz.ch.db.mapper.distribution"
<javaClientGenerator
type=
"XMLMAPPER"
targetPackage=
"com.wwdz.ch.db.mapper.distribution"
targetProject=
"ch-dao/src/main/java"
/>
targetProject=
"ch-dao/src/main/java"
/>
<table
tableName=
"s
hop_white_list
"
enableCountByExample=
"true"
enableUpdateByExample=
"true"
enableDeleteByExample=
"true"
enableSelectByExample=
"true"
selectByExampleQueryId=
"true"
>
<table
tableName=
"s
upplier_item
"
enableCountByExample=
"true"
enableUpdateByExample=
"true"
enableDeleteByExample=
"true"
enableSelectByExample=
"true"
selectByExampleQueryId=
"true"
>
<generatedKey
column=
"id"
sqlStatement=
"Mysql"
identity=
"true"
/>
<generatedKey
column=
"id"
sqlStatement=
"Mysql"
identity=
"true"
/>
</table>
</table>
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/WxPayCallbackController.java
View file @
23eea9a7
...
@@ -4,9 +4,11 @@ import com.wechat.pay.java.core.RSAAutoCertificateConfig;
...
@@ -4,9 +4,11 @@ import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import
com.wechat.pay.java.core.notification.NotificationParser
;
import
com.wechat.pay.java.core.notification.NotificationParser
;
import
com.wechat.pay.java.core.notification.RequestParam
;
import
com.wechat.pay.java.core.notification.RequestParam
;
import
com.wechat.pay.java.service.payments.model.Transaction
;
import
com.wechat.pay.java.service.payments.model.Transaction
;
import
com.wwdz.ch.core.api.OfficialAccountApi
;
import
com.wwdz.ch.core.api.wxpay.WxPayServiceApi
;
import
com.wwdz.ch.core.api.wxpay.WxPayServiceApi
;
import
com.wwdz.ch.core.consts.DistributionEnum
;
import
com.wwdz.ch.core.consts.DistributionEnum
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.PriceUtil
;
import
com.wwdz.ch.core.util.RedisUtils
;
import
com.wwdz.ch.core.util.RedisUtils
;
import
com.wwdz.ch.core.util.TimeUtil
;
import
com.wwdz.ch.core.util.TimeUtil
;
import
com.wwdz.ch.db.dao.distribution.DistributionOrderDao
;
import
com.wwdz.ch.db.dao.distribution.DistributionOrderDao
;
...
@@ -16,8 +18,11 @@ import com.wwdz.ch.db.domain.distribution.DistributionOrder;
...
@@ -16,8 +18,11 @@ import com.wwdz.ch.db.domain.distribution.DistributionOrder;
import
com.wwdz.ch.db.domain.distribution.DistributorProfit
;
import
com.wwdz.ch.db.domain.distribution.DistributorProfit
;
import
com.wwdz.ch.db.domain.distribution.SupplierItem
;
import
com.wwdz.ch.db.domain.distribution.SupplierItem
;
import
com.wwdz.ch.db.dto.request.distribution.DistributionOrderRequestDto
;
import
com.wwdz.ch.db.dto.request.distribution.DistributionOrderRequestDto
;
import
com.wwdz.ch.wx.entity.PayNoticeMsg
;
import
com.wwdz.ch.wx.service.distribution.SendMsgService
;
import
com.wwdz.ch.wx.service.distribution.SupplierItemService
;
import
com.wwdz.ch.wx.service.distribution.SupplierItemService
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -65,6 +70,12 @@ public class WxPayCallbackController {
...
@@ -65,6 +70,12 @@ public class WxPayCallbackController {
@Autowired
@Autowired
SupplierItemService
supplierItemService
;
SupplierItemService
supplierItemService
;
@Autowired
OfficialAccountApi
officialAccountApi
;
@Autowired
SendMsgService
sendMsgService
;
@RequestMapping
(
value
=
"/getPayNotify"
)
@RequestMapping
(
value
=
"/getPayNotify"
)
public
synchronized
String
payNotify
(
HttpServletRequest
request
)
throws
IOException
{
public
synchronized
String
payNotify
(
HttpServletRequest
request
)
throws
IOException
{
logger
.
info
(
"------------------ 收到微信支付回调通知 ------------------"
);
logger
.
info
(
"------------------ 收到微信支付回调通知 ------------------"
);
...
@@ -130,6 +141,8 @@ public class WxPayCallbackController {
...
@@ -130,6 +141,8 @@ public class WxPayCallbackController {
}
}
}
}
}
}
returnMap
.
put
(
"code"
,
"SUCCESS"
);
returnMap
.
put
(
"code"
,
"SUCCESS"
);
returnMap
.
put
(
"message"
,
"成功"
);
returnMap
.
put
(
"message"
,
"成功"
);
return
JsonUtils
.
from
(
returnMap
);
return
JsonUtils
.
from
(
returnMap
);
...
@@ -189,6 +202,24 @@ public class WxPayCallbackController {
...
@@ -189,6 +202,24 @@ public class WxPayCallbackController {
//更新库存
//更新库存
supplierItemService
.
reduceStock
(
distributionOrder
.
getItemId
(),
distributionOrder
.
getItemNum
());
supplierItemService
.
reduceStock
(
distributionOrder
.
getItemId
(),
distributionOrder
.
getItemNum
());
logger
.
info
(
">>>>>>>>>>>> 微信支付回调通知处理成功,更新订单状态和商品库存 <<<<<<<<<<<<"
);
logger
.
info
(
">>>>>>>>>>>> 微信支付回调通知处理成功,更新订单状态和商品库存 <<<<<<<<<<<<"
);
//用户支付成功,发送模板信息通知分销商
try
{
String
openId
=
sendMsgService
.
getOpenIdByUserId
(
distributionOrder
.
getSellerId
());
if
(
StringUtils
.
hasLength
(
openId
))
{
PayNoticeMsg
payNoticeMsg
=
new
PayNoticeMsg
();
payNoticeMsg
.
setDistributionOrderId
(
distributionOrderId
);
payNoticeMsg
.
setItemName
(
supplierItem
.
getName
());
payNoticeMsg
.
setItemNum
(
distributionOrder
.
getItemNum
());
payNoticeMsg
.
setAmount
(
PriceUtil
.
convertPriceFenToYuan
(
distributionOrder
.
getAmount
()));
payNoticeMsg
.
setPayTime
(
TimeUtil
.
wxTimeConvert
(
payTime
));
sendMsgService
.
sendPayTempletMsg
(
openId
,
payNoticeMsg
);
}
else
{
logger
.
info
(
">>>>> 分销商id :{}, 获取openid失败 <<<<<"
,
distributionOrder
.
getSellerId
());
}
}
catch
(
Exception
e
)
{
logger
.
info
(
"用户支付成功,向分销商发送模板信息失败:{}"
,
e
);
}
return
Result
.
success
();
return
Result
.
success
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
info
(
">>>>>>>>>>>> 微信支付回调通知处理失败 error :{}"
,
e
);
logger
.
info
(
">>>>>>>>>>>> 微信支付回调通知处理失败 error :{}"
,
e
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
View file @
23eea9a7
...
@@ -42,7 +42,8 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
...
@@ -42,7 +42,8 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
"/officialAccountCallback/**"
,
"/wxPayCallback/**"
,
"/officialAccountCallback/**"
,
"/wxPayCallback/**"
,
"/imCallback/**"
,
"/wx/category/**"
,
"/imCallback/**"
,
"/wx/category/**"
,
"/wx/consignSale/**"
,
"/wx/item/**"
,
"/wx/consignSale/**"
,
"/wx/item/**"
,
"/wx/returnOrder/**"
,
"/wx/supplierItem/**"
,
"/wx/shareRecord/**"
,
"/wx/distributionOrder/**"
,
"/wx/selfPage/**"
"/wx/returnOrder/**"
,
"/wx/supplierItem/**"
,
"/wx/shareRecord/**"
,
"/wx/distributionOrder/**"
,
"/wx/selfPage/**"
/* "/wx/officialAccount/**",
/* "/wx/officialAccount/**",
"/wx/item/**",
"/wx/item/**",
"/wx/aiAssistant/**",
"/wx/aiAssistant/**",
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/DeliveryNoticeMsg.java
0 → 100644
View file @
23eea9a7
package
com.wwdz.ch.wx.entity
;
import
com.wwdz.ch.core.entity.AbstractSubscribeMsg
;
import
com.xxdxxs.entity.Entity
;
import
com.xxdxxs.utils.DateUtils
;
import
lombok.Data
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* 发货通知消息
*/
@Data
public
class
DeliveryNoticeMsg
implements
Entity
,
AbstractSubscribeMsg
{
private
String
templetId
;
/**
* 分销订单号
*/
private
String
distributionOrderId
;
/**
* 商品名称
*/
private
String
itemName
;
/**
* 快递单号
*/
private
String
waybill
;
/**
* 收货地址
*/
private
String
address
;
/**
* 发货时间
*/
private
Date
deliveryTime
;
@Override
public
Map
<
String
,
Object
>
getTempletParam
()
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"character_string3"
,
new
HashMap
(){{
put
(
"value"
,
distributionOrderId
);}});
map
.
put
(
"thing14"
,
new
HashMap
(){{
put
(
"value"
,
itemName
);}});
map
.
put
(
"character_string8"
,
new
HashMap
(){{
put
(
"value"
,
waybill
);}});
map
.
put
(
"thing17"
,
new
HashMap
(){{
put
(
"value"
,
address
);}});
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy年MM月dd日 HH:mm:ss"
,
Locale
.
CHINESE
);
String
formattedDate
=
sdf
.
format
(
deliveryTime
);
map
.
put
(
"time10"
,
new
HashMap
(){{
put
(
"value"
,
formattedDate
);}});
return
map
;
}
@Override
public
String
getTempletId
()
{
return
templetId
;
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/PayNoticeMsg.java
0 → 100644
View file @
23eea9a7
package
com.wwdz.ch.wx.entity
;
import
com.wwdz.ch.core.entity.AbstractSubscribeMsg
;
import
com.xxdxxs.entity.Entity
;
import
com.xxdxxs.utils.DateUtils
;
import
lombok.Data
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* 支付通知消息
*/
@Data
public
class
PayNoticeMsg
implements
Entity
,
AbstractSubscribeMsg
{
private
String
templetId
;
/**
* 分销订单号
*/
private
String
distributionOrderId
;
/**
* 商品名称
*/
private
String
itemName
;
/**
* 商品数量
*/
private
Integer
itemNum
;
/**
* 订单金额
*/
private
String
amount
;
/**
* 支付时间
*/
private
String
payTime
;
@Override
public
Map
<
String
,
Object
>
getTempletParam
()
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"character_string2"
,
new
HashMap
(){{
put
(
"value"
,
distributionOrderId
);}});
map
.
put
(
"thing6"
,
new
HashMap
(){{
put
(
"value"
,
itemName
);}});
map
.
put
(
"number8"
,
new
HashMap
(){{
put
(
"value"
,
itemNum
);}});
map
.
put
(
"amount12"
,
new
HashMap
(){{
put
(
"value"
,
amount
);}});
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy年MM月dd日 HH:mm:ss"
,
Locale
.
CHINESE
);
String
formattedDate
=
sdf
.
format
(
DateUtils
.
parseString
(
payTime
));
map
.
put
(
"time14"
,
new
HashMap
(){{
put
(
"value"
,
formattedDate
);}});
return
map
;
}
@Override
public
String
getTempletId
()
{
return
templetId
;
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/SignedNoticeMsg.java
0 → 100644
View file @
23eea9a7
package
com.wwdz.ch.wx.entity
;
import
com.wwdz.ch.core.entity.AbstractSubscribeMsg
;
import
com.xxdxxs.entity.Entity
;
import
com.xxdxxs.utils.DateUtils
;
import
lombok.Data
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* 确认收货通知消息
*/
@Data
public
class
SignedNoticeMsg
implements
Entity
,
AbstractSubscribeMsg
{
private
String
templetId
;
/**
* 分销订单号
*/
private
String
distributionOrderId
;
/**
* 商品名称
*/
private
String
itemName
;
/**
* 付款金额
*/
private
String
amount
;
/**
* 签收时间
*/
private
Date
signedTime
;
@Override
public
Map
<
String
,
Object
>
getTempletParam
()
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"character_string5"
,
new
HashMap
(){{
put
(
"value"
,
distributionOrderId
);}});
map
.
put
(
"thing1"
,
new
HashMap
(){{
put
(
"value"
,
itemName
);}});
map
.
put
(
"amount2"
,
new
HashMap
(){{
put
(
"value"
,
amount
);}});
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy年MM月dd日 HH:mm:ss"
,
Locale
.
CHINESE
);
String
formattedDate
=
sdf
.
format
(
signedTime
);
map
.
put
(
"time4"
,
new
HashMap
(){{
put
(
"value"
,
formattedDate
);}});
return
map
;
}
@Override
public
String
getTempletId
()
{
return
templetId
;
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/DistributionOrderServiceImpl.java
View file @
23eea9a7
...
@@ -21,9 +21,14 @@ import com.wwdz.ch.db.domain.distribution.SupplierItem;
...
@@ -21,9 +21,14 @@ import com.wwdz.ch.db.domain.distribution.SupplierItem;
import
com.wwdz.ch.db.dto.request.ConsignSaleRequestDto
;
import
com.wwdz.ch.db.dto.request.ConsignSaleRequestDto
;
import
com.wwdz.ch.db.dto.request.distribution.DistributionOrderRequestDto
;
import
com.wwdz.ch.db.dto.request.distribution.DistributionOrderRequestDto
;
import
com.wwdz.ch.db.dto.request.distribution.SupplierItemRequestDto
;
import
com.wwdz.ch.db.dto.request.distribution.SupplierItemRequestDto
;
import
com.wwdz.ch.wx.entity.DeliveryNoticeMsg
;
import
com.wwdz.ch.wx.entity.PayNoticeMsg
;
import
com.wwdz.ch.wx.entity.SignedNoticeMsg
;
import
com.wwdz.ch.wx.entity.vo.distribution.DistributionOrderDetailVo
;
import
com.wwdz.ch.wx.entity.vo.distribution.DistributionOrderDetailVo
;
import
com.wwdz.ch.wx.entity.vo.distribution.DistributionOrderVo
;
import
com.wwdz.ch.wx.entity.vo.distribution.DistributionOrderVo
;
import
com.wwdz.ch.wx.service.distribution.DistributionOrderService
;
import
com.wwdz.ch.wx.service.distribution.DistributionOrderService
;
import
com.wwdz.ch.wx.service.distribution.SendMsgService
;
import
com.xxdxxs.utils.DateUtils
;
import
com.xxdxxs.utils.EntityMapper
;
import
com.xxdxxs.utils.EntityMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -67,6 +72,9 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
...
@@ -67,6 +72,9 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
@Autowired
@Autowired
DistributorProfitDao
distributorProfitDao
;
DistributorProfitDao
distributorProfitDao
;
@Autowired
SendMsgService
sendMsgService
;
@Override
@Override
public
Result
createDistributionOrder
(
DistributionOrderRequestDto
dto
)
{
public
Result
createDistributionOrder
(
DistributionOrderRequestDto
dto
)
{
try
{
try
{
...
@@ -178,6 +186,26 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
...
@@ -178,6 +186,26 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
public
Result
confirmSigned
(
DistributionOrderRequestDto
dto
)
{
public
Result
confirmSigned
(
DistributionOrderRequestDto
dto
)
{
try
{
try
{
distributionOrderDao
.
updateState
(
dto
.
getDistributionOrderId
(),
DistributionEnum
.
DistributionOrderStateEnum
.
FINISH
.
getCode
());
distributionOrderDao
.
updateState
(
dto
.
getDistributionOrderId
(),
DistributionEnum
.
DistributionOrderStateEnum
.
FINISH
.
getCode
());
String
distributionOrderId
=
dto
.
getDistributionOrderId
();
DistributionOrder
distributionOrder
=
distributionOrderDao
.
findById
(
distributionOrderId
);
//用户确认收货,发送模板信息通知分销商
try
{
SignedNoticeMsg
signedNoticeMsg
=
new
SignedNoticeMsg
();
signedNoticeMsg
.
setDistributionOrderId
(
distributionOrderId
);
signedNoticeMsg
.
setAmount
(
PriceUtil
.
convertPriceFenToYuan
(
distributionOrder
.
getAmount
()));
SupplierItem
supplierItem
=
supplierItemDao
.
findById
(
distributionOrder
.
getItemId
());
signedNoticeMsg
.
setItemName
(
supplierItem
.
getName
());
signedNoticeMsg
.
setSignedTime
(
new
Date
());
//发送给卖家
String
sellerOpenId
=
sendMsgService
.
getOpenIdByUserId
(
distributionOrder
.
getSellerId
());
if
(
com
.
xxdxxs
.
utils
.
StringUtils
.
hasLength
(
sellerOpenId
))
{
sendMsgService
.
sendSignedTempletMsg
(
sellerOpenId
,
signedNoticeMsg
);
}
else
{
logger
.
info
(
">>>>> 分销商id :{}, 获取openid失败,无法发送模板信息 <<<<<"
,
distributionOrder
.
getSellerId
());
}
}
catch
(
Exception
e
)
{
logger
.
info
(
"分销订单发货通知模板信息发送失败:{}"
,
e
);
}
return
Result
.
success
();
return
Result
.
success
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
info
(
"用户确认收货失败 error: {}"
,
e
);
logger
.
info
(
"用户确认收货失败 error: {}"
,
e
);
...
@@ -193,13 +221,40 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
...
@@ -193,13 +221,40 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
if
(
distributionOrder
.
getState
()
!=
DistributionEnum
.
DistributionOrderStateEnum
.
PRE_SEND
.
getCode
())
{
if
(
distributionOrder
.
getState
()
!=
DistributionEnum
.
DistributionOrderStateEnum
.
PRE_SEND
.
getCode
())
{
return
Result
.
failed
(
"订单状态错误,不能发货"
);
return
Result
.
failed
(
"订单状态错误,不能发货"
);
}
}
Date
now
=
new
Date
();
DistributionOrder
orderUpdateDto
=
new
DistributionOrder
();
DistributionOrder
orderUpdateDto
=
new
DistributionOrder
();
orderUpdateDto
.
setDistributionOrderId
(
distributionOrderId
);
orderUpdateDto
.
setDistributionOrderId
(
distributionOrderId
);
orderUpdateDto
.
setLogisticsCode
(
dto
.
getLogisticsCode
());
orderUpdateDto
.
setLogisticsCode
(
dto
.
getLogisticsCode
());
orderUpdateDto
.
setWaybill
(
dto
.
getWaybill
());
orderUpdateDto
.
setWaybill
(
dto
.
getWaybill
());
orderUpdateDto
.
setDeliveryTime
(
n
ew
Date
()
);
orderUpdateDto
.
setDeliveryTime
(
n
ow
);
orderUpdateDto
.
setState
(
DistributionEnum
.
DistributionOrderStateEnum
.
PRE_SIGNED
.
getCode
());
orderUpdateDto
.
setState
(
DistributionEnum
.
DistributionOrderStateEnum
.
PRE_SIGNED
.
getCode
());
distributionOrderDao
.
update
(
orderUpdateDto
);
distributionOrderDao
.
update
(
orderUpdateDto
);
//发货成功,发送模板信息通知分销商和用户
try
{
DeliveryNoticeMsg
deliveryNoticeMsg
=
new
DeliveryNoticeMsg
();
deliveryNoticeMsg
.
setDistributionOrderId
(
distributionOrderId
);
deliveryNoticeMsg
.
setWaybill
(
dto
.
getWaybill
());
deliveryNoticeMsg
.
setAddress
(
distributionOrder
.
getReceiverName
()
+
" "
+
distributionOrder
.
getReceiverPhone
()
+
" "
+
distributionOrder
.
getReceiverAddress
());
SupplierItem
supplierItem
=
supplierItemDao
.
findById
(
distributionOrder
.
getItemId
());
deliveryNoticeMsg
.
setItemName
(
supplierItem
.
getName
());
deliveryNoticeMsg
.
setDeliveryTime
(
now
);
//发送给卖家
String
sellerOpenId
=
sendMsgService
.
getOpenIdByUserId
(
distributionOrder
.
getSellerId
());
if
(
com
.
xxdxxs
.
utils
.
StringUtils
.
hasLength
(
sellerOpenId
))
{
sendMsgService
.
sendDeliveryTempletMsg
(
sellerOpenId
,
deliveryNoticeMsg
);
}
else
{
logger
.
info
(
">>>>> 分销商id :{}, 获取openid失败 <<<<<"
,
distributionOrder
.
getSellerId
());
}
//发送给买家
if
(
com
.
xxdxxs
.
utils
.
StringUtils
.
hasLength
(
distributionOrder
.
getBuyerOpenid
()))
{
sendMsgService
.
sendDeliveryTempletMsg
(
distributionOrder
.
getBuyerOpenid
(),
deliveryNoticeMsg
);
}
else
{
logger
.
info
(
">>>>> 买家openid为空, 发送消息失败 <<<<<"
);
}
}
catch
(
Exception
e
)
{
logger
.
info
(
"分销订单发货通知模板信息发送失败:{}"
,
e
);
}
return
Result
.
success
();
return
Result
.
success
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
info
(
"发货失败 error: {}"
,
e
);
logger
.
info
(
"发货失败 error: {}"
,
e
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/SendMsgServiceImpl.java
0 → 100644
View file @
23eea9a7
package
com.wwdz.ch.wx.impl.distribution
;
import
com.wwdz.ch.core.api.OfficialAccountApi
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.OkHttpUtil
;
import
com.wwdz.ch.db.dao.OfficialAccountSubscribeRecordDao
;
import
com.wwdz.ch.db.dao.UserDao
;
import
com.wwdz.ch.db.domain.OfficialAccountSubscribeRecord
;
import
com.wwdz.ch.db.domain.User
;
import
com.wwdz.ch.wx.entity.DeliveryNoticeMsg
;
import
com.wwdz.ch.wx.entity.PayNoticeMsg
;
import
com.wwdz.ch.wx.entity.SignedNoticeMsg
;
import
com.wwdz.ch.wx.service.distribution.SendMsgService
;
import
com.xxdxxs.utils.JsonUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 发送模板消息
*/
@Service
public
class
SendMsgServiceImpl
implements
SendMsgService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SendMsgServiceImpl
.
class
);
private
final
static
String
SEND_MSG_URL
=
"https://api.weixin.qq.com/cgi-bin/message/template/send"
;
@Value
(
"${dts.wx.pay-templetId}"
)
private
String
PAY_TEMPLETID
;
@Value
(
"${dts.wx.delivery-templetId}"
)
private
String
DELIVERY_TEMPLETID
;
@Value
(
"${dts.wx.signed-templetId}"
)
private
String
SIGNED_TEMPLETID
;
@Value
(
"${dts.wx.app-id}"
)
private
String
APPLET_APPID
;
@Value
(
"${dts.wx.distribution-msg-url}"
)
private
String
DISTRIBUTION_MSG_URL
;
@Autowired
OfficialAccountApi
officialAccountApi
;
@Autowired
UserDao
userDao
;
@Autowired
OfficialAccountSubscribeRecordDao
officialAccountSubscribeRecordDao
;
@Override
public
Result
sendPayTempletMsg
(
String
openId
,
PayNoticeMsg
payNoticeMsg
)
{
String
token
=
officialAccountApi
.
getAccessToken
();
String
url
=
SEND_MSG_URL
+
"?access_token="
+
token
;
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"touser"
,
openId
);
map
.
put
(
"template_id"
,
PAY_TEMPLETID
);
Map
<
String
,
Object
>
miniprogramMap
=
new
HashMap
<>();
miniprogramMap
.
put
(
"appid"
,
APPLET_APPID
);
StringBuffer
stringBuffer
=
new
StringBuffer
(
DISTRIBUTION_MSG_URL
);
stringBuffer
.
append
(
"?orderId="
+
payNoticeMsg
.
getDistributionOrderId
());
miniprogramMap
.
put
(
"pagepath"
,
stringBuffer
.
toString
());
map
.
put
(
"miniprogram"
,
miniprogramMap
);
map
.
put
(
"data"
,
payNoticeMsg
.
getTempletParam
());
logger
.
info
(
"============ 分销订单支付通知模板消息内容 : {}"
,
JsonUtils
.
fromMap
(
map
));
okHttpUtil
.
addParams
(
map
);
okHttpUtil
.
post
(
true
);
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"openid : {}, 发送分销订单支付通知模板消息 response :{}"
,
openId
,
responseStr
);
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errcode"
);
String
errmsg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
if
(!
"0"
.
equals
(
errorCode
))
{
logger
.
error
(
"openid : {}, 发送分销订单支付通知模板消息, errorCode : {}, errmsg : {} "
,
openId
,
errorCode
,
errmsg
);
return
Result
.
failed
();
}
logger
.
info
(
"============= 发送分销订单支付通知模板消息成功 ==========="
);
return
Result
.
success
();
}
@Override
public
Result
sendDeliveryTempletMsg
(
String
openId
,
DeliveryNoticeMsg
deliveryNoticeMsg
)
{
String
token
=
officialAccountApi
.
getAccessToken
();
String
url
=
SEND_MSG_URL
+
"?access_token="
+
token
;
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"touser"
,
openId
);
map
.
put
(
"template_id"
,
DELIVERY_TEMPLETID
);
Map
<
String
,
Object
>
miniprogramMap
=
new
HashMap
<>();
miniprogramMap
.
put
(
"appid"
,
APPLET_APPID
);
StringBuffer
stringBuffer
=
new
StringBuffer
(
DISTRIBUTION_MSG_URL
);
stringBuffer
.
append
(
"?orderId="
+
deliveryNoticeMsg
.
getDistributionOrderId
());
miniprogramMap
.
put
(
"pagepath"
,
stringBuffer
.
toString
());
map
.
put
(
"miniprogram"
,
miniprogramMap
);
map
.
put
(
"data"
,
deliveryNoticeMsg
.
getTempletParam
());
logger
.
info
(
"============ 分销订单发货通知模板消息内容 : {}"
,
JsonUtils
.
fromMap
(
map
));
okHttpUtil
.
addParams
(
map
);
okHttpUtil
.
post
(
true
);
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"openid : {}, 发送分销订单发货通知模板消息 response :{}"
,
openId
,
responseStr
);
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errcode"
);
String
errmsg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
if
(!
"0"
.
equals
(
errorCode
))
{
logger
.
error
(
"openid : {}, 发送分销订单发货通知模板消息, errorCode : {}, errmsg : {} "
,
openId
,
errorCode
,
errmsg
);
return
Result
.
failed
();
}
logger
.
info
(
"============= 发送分销订单发货通知模板消息成功 ==========="
);
return
Result
.
success
();
}
@Override
public
Result
sendSignedTempletMsg
(
String
openId
,
SignedNoticeMsg
signedNoticeMsg
)
{
String
token
=
officialAccountApi
.
getAccessToken
();
String
url
=
SEND_MSG_URL
+
"?access_token="
+
token
;
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"touser"
,
openId
);
map
.
put
(
"template_id"
,
SIGNED_TEMPLETID
);
Map
<
String
,
Object
>
miniprogramMap
=
new
HashMap
<>();
miniprogramMap
.
put
(
"appid"
,
APPLET_APPID
);
StringBuffer
stringBuffer
=
new
StringBuffer
(
DISTRIBUTION_MSG_URL
);
stringBuffer
.
append
(
"?orderId="
+
signedNoticeMsg
.
getDistributionOrderId
());
miniprogramMap
.
put
(
"pagepath"
,
stringBuffer
.
toString
());
map
.
put
(
"miniprogram"
,
miniprogramMap
);
map
.
put
(
"data"
,
signedNoticeMsg
.
getTempletParam
());
logger
.
info
(
"============ 分销订单签收通知模板消息内容 : {}"
,
JsonUtils
.
fromMap
(
map
));
okHttpUtil
.
addParams
(
map
);
okHttpUtil
.
post
(
true
);
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"openid : {}, 发送分销订单签收通知模板消息 response :{}"
,
openId
,
responseStr
);
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errcode"
);
String
errmsg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
if
(!
"0"
.
equals
(
errorCode
))
{
logger
.
error
(
"openid : {}, 发送分销订单签收通知模板消息, errorCode : {}, errmsg : {} "
,
openId
,
errorCode
,
errmsg
);
return
Result
.
failed
();
}
logger
.
info
(
"============= 发送分销订单签收通知模板消息成功 ==========="
);
return
Result
.
success
();
}
@Override
public
String
getOpenIdByUserId
(
long
userId
)
{
//先查询寄售单用户信息
User
user
=
userDao
.
queryById
(
userId
);
String
unionId
=
user
.
getWeixinUnionid
();
OfficialAccountSubscribeRecord
officialAccountSubscribeRecord
=
officialAccountSubscribeRecordDao
.
findOne
(
unionId
);
//没有订阅
if
(
officialAccountSubscribeRecord
==
null
||
officialAccountSubscribeRecord
.
getEnabled
().
intValue
()
==
0
)
{
logger
.
info
(
">>>>>>>>>> 用户 unionId = {} ,尚未订阅公众号,无法推送消息 <<<<<<<<<<<"
);
return
null
;
}
String
openId
=
officialAccountSubscribeRecord
.
getOpenid
();
return
openId
;
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/distribution/SendMsgService.java
0 → 100644
View file @
23eea9a7
package
com.wwdz.ch.wx.service.distribution
;
import
com.wwdz.ch.core.entity.AbstractSubscribeMsg
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.wx.entity.DeliveryNoticeMsg
;
import
com.wwdz.ch.wx.entity.PayNoticeMsg
;
import
com.wwdz.ch.wx.entity.SignedNoticeMsg
;
public
interface
SendMsgService
{
Result
sendPayTempletMsg
(
String
openId
,
PayNoticeMsg
payNoticeMsg
);
Result
sendDeliveryTempletMsg
(
String
openId
,
DeliveryNoticeMsg
deliveryNoticeMsg
);
Result
sendSignedTempletMsg
(
String
openId
,
SignedNoticeMsg
signedNoticeMsg
);
String
getOpenIdByUserId
(
long
userId
);
}
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