多笔立减金
This commit is contained in:
parent
413b8100d8
commit
d01900b519
|
|
@ -118,6 +118,10 @@ aliYunSms:
|
||||||
signName: 蓝色兄弟
|
signName: 蓝色兄弟
|
||||||
templateWarning: "SMS_489660721"
|
templateWarning: "SMS_489660721"
|
||||||
|
|
||||||
|
tripartite:
|
||||||
|
qiXing:
|
||||||
|
appKey: "DrY1zLkOH01q0sN66vrmkdpbWsyb41ho"
|
||||||
|
|
||||||
#配置日志
|
#配置日志
|
||||||
logs:
|
logs:
|
||||||
business: business.log #业务日志路径:如果不写日志,则不配置或配置为空
|
business: business.log #业务日志路径:如果不写日志,则不配置或配置为空
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,25 @@
|
||||||
package bo
|
package bo
|
||||||
|
|
||||||
|
import "github.com/go-playground/validator/v10"
|
||||||
|
|
||||||
type QiXingRequestBo struct {
|
type QiXingRequestBo struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content" validate:"required"`
|
||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp" validate:"required"`
|
||||||
Ciphertext string `json:"ciphertext"`
|
Ciphertext string `json:"ciphertext" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QiXingResponse 响应结构体 {"msg":"SUCCESS"} / {"msg":"操作成功"}
|
// QiXingResponse 响应结构体 {"msg":"SUCCESS"} / {"msg":"操作成功"}
|
||||||
type QiXingResponse struct {
|
type QiXingResponse struct {
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *QiXingRequestBo) Validate() error {
|
||||||
|
|
||||||
|
if err := validator.New().Struct(c); err != nil {
|
||||||
|
for _, err = range err.(validator.ValidationErrors) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,38 @@ func queryUsed(useNum *int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMd5(t *testing.T) {
|
func TestMd5(t *testing.T) {
|
||||||
s := Md5(`{"product_no":"","start_time":"2025-04-20 09:00:00","end_time":"2025-05-01 00:00:00"}`)
|
|
||||||
t.Log(s)
|
jsonStr := `{
|
||||||
|
"id": "4ab2699d-e91d-5460-9810-25fd6d4c69a5",
|
||||||
|
"create_time": "2025-12-08T17:54:24+08:00",
|
||||||
|
"resource_type": "encrypt-resource",
|
||||||
|
"event_type": "COUPON.USE",
|
||||||
|
"summary": "代金券核销通知",
|
||||||
|
"original_type": "coupon",
|
||||||
|
"associated_data": "coupon",
|
||||||
|
"plain_text": {
|
||||||
|
"stock_creator_mchid": "1652465541",
|
||||||
|
"stock_id": "21386484",
|
||||||
|
"coupon_id": "142388354994",
|
||||||
|
"coupon_name": "银行卡多笔立减",
|
||||||
|
"description": "",
|
||||||
|
"status": "SENDED",
|
||||||
|
"create_time": "2025-12-08T17:50:48+08:00",
|
||||||
|
"coupon_type": "NORMAL",
|
||||||
|
"no_cash": false,
|
||||||
|
"singleitem": false,
|
||||||
|
"business_type": "",
|
||||||
|
"consume_information": {
|
||||||
|
"consume_time": "2025-12-08T17:54:24+08:00",
|
||||||
|
"consume_mchid": "1274938601",
|
||||||
|
"transaction_id": "4200002996202512083063051834",
|
||||||
|
"consume_amount": 16
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
ciphertext := Md5(jsonStr)
|
||||||
|
t.Log(ciphertext)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLength(t *testing.T) {
|
func TestLength(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-kratos/kratos/v2/log"
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
|
|
@ -40,6 +41,11 @@ func (srv *TripartiteService) QiXingNotify(ctx http.Context) error {
|
||||||
return srv.ResponseErr(ctx, fmt.Sprintf("json unmarshal bodyBytes error: %v", err))
|
return srv.ResponseErr(ctx, fmt.Sprintf("json unmarshal bodyBytes error: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = req.Validate(); err != nil {
|
||||||
|
log.Errorf("qixing notify req validate err ip:%s,error:%v,body:%s", ip, err, string(bodyBytes))
|
||||||
|
return srv.ResponseErr(ctx, fmt.Sprintf("validate req error: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
// 加密校验串,(生成规则:MD5(content+公钥))
|
// 加密校验串,(生成规则:MD5(content+公钥))
|
||||||
if srv.bc.Tripartite.QiXing.AppKey == "" {
|
if srv.bc.Tripartite.QiXing.AppKey == "" {
|
||||||
return srv.ResponseErr(ctx, "qixing appKey is empty")
|
return srv.ResponseErr(ctx, "qixing appKey is empty")
|
||||||
|
|
@ -51,8 +57,14 @@ func (srv *TripartiteService) QiXingNotify(ctx http.Context) error {
|
||||||
return srv.ResponseErr(ctx, "sign error")
|
return srv.ResponseErr(ctx, "sign error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxNotifyDataStr, err := base64.StdEncoding.DecodeString(req.Content)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("qixing notify wxNotifyDataStr err ip:%s,error:%v,body:%s", ip, err, string(bodyBytes))
|
||||||
|
return srv.ResponseErr(ctx, fmt.Sprintf("base64 decode req content error: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
var wxNotifyData *bo.WechatVoucherNotifyBo
|
var wxNotifyData *bo.WechatVoucherNotifyBo
|
||||||
if err = json.Unmarshal([]byte(req.Content), &wxNotifyData); err != nil {
|
if err = json.Unmarshal(wxNotifyDataStr, &wxNotifyData); err != nil {
|
||||||
log.Errorf("qixing notify wxNotifyData err ip:%s,error:%v,body:%s", ip, err, string(bodyBytes))
|
log.Errorf("qixing notify wxNotifyData err ip:%s,error:%v,body:%s", ip, err, string(bodyBytes))
|
||||||
return srv.ResponseErr(ctx, fmt.Sprintf("json unmarshal wxNotifyData error: %v", err))
|
return srv.ResponseErr(ctx, fmt.Sprintf("json unmarshal wxNotifyData error: %v", err))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
"voucher/internal/biz/bo"
|
||||||
|
"voucher/internal/pkg/helper"
|
||||||
|
)
|
||||||
|
|
||||||
func Test_MarketingSend(t *testing.T) {
|
func Test_MarketingSend(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|
@ -47,3 +54,50 @@ func Test_MarketingQuery(t *testing.T) {
|
||||||
//openid不是自己的appid下的喔,这也能查询到吗”
|
//openid不是自己的appid下的喔,这也能查询到吗”
|
||||||
//不行的,需要是在自己appid下的才能查到
|
//不行的,需要是在自己appid下的才能查到
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_QixingNotifyData(t *testing.T) {
|
||||||
|
|
||||||
|
wxBody := `{
|
||||||
|
"id": "4ab2699d-e91d-5460-9810-25fd6d4c69a5",
|
||||||
|
"create_time": "2025-12-08T17:54:24+08:00",
|
||||||
|
"resource_type": "encrypt-resource",
|
||||||
|
"event_type": "COUPON.USE",
|
||||||
|
"summary": "代金券核销通知",
|
||||||
|
"original_type": "coupon",
|
||||||
|
"associated_data": "coupon",
|
||||||
|
"plain_text": {
|
||||||
|
"stock_creator_mchid": "1652465541",
|
||||||
|
"stock_id": "21386484",
|
||||||
|
"coupon_id": "142388354994",
|
||||||
|
"coupon_name": "银行卡多笔立减",
|
||||||
|
"description": "",
|
||||||
|
"status": "SENDED",
|
||||||
|
"create_time": "2025-12-08T17:50:48+08:00",
|
||||||
|
"coupon_type": "NORMAL",
|
||||||
|
"no_cash": false,
|
||||||
|
"singleitem": false,
|
||||||
|
"business_type": "",
|
||||||
|
"consume_information": {
|
||||||
|
"consume_time": "2025-12-08T17:54:24+08:00",
|
||||||
|
"consume_mchid": "1274938601",
|
||||||
|
"transaction_id": "4200002996202512083063051834",
|
||||||
|
"consume_amount": 16
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
content := base64.StdEncoding.EncodeToString([]byte(wxBody))
|
||||||
|
|
||||||
|
ciphertext := helper.Md5(content + "DrY1zLkOH01q0sN66vrmkdpbWsyb41ho")
|
||||||
|
|
||||||
|
req := bo.QiXingRequestBo{
|
||||||
|
Content: content,
|
||||||
|
Timestamp: time.Now().UnixMilli(),
|
||||||
|
Ciphertext: ciphertext,
|
||||||
|
}
|
||||||
|
|
||||||
|
b, _ := json.Marshal(req)
|
||||||
|
|
||||||
|
t.Log(string(b))
|
||||||
|
// {"content":"base64(微信通知json对象数据)","timestamp":1765447477945,"ciphertext":"md5(base64(微信通知json对象数据)+key)"}
|
||||||
|
//t.Logf(`{"content":"%s","timestamp":122345677890,"ciphertext":"%s"}`, content, ciphertext)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue