voucher/internal/pkg/helper/utils_test.go

97 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package helper
import (
"encoding/json"
"fmt"
"testing"
"time"
"voucher/internal/biz/bo"
)
func TestHashMod(t *testing.T) {
serverId := HashMod("1dfsfdsfsddf12dddd5451212iodewnsanf2")
fmt.Println(serverId)
}
func TestNoticeTime(t *testing.T) {
now := time.Now()
// 获取七天前的日期
noticeStartDay := now.AddDate(0, 0, -15)
// 获取七天前 00:00:00 的时间
startTime := time.Date(noticeStartDay.Year(), noticeStartDay.Month(), noticeStartDay.Day(), 0, 0, 0, 0, noticeStartDay.Location())
noticeEndDay := now.AddDate(0, 0, -1)
// 获取昨天 23:59:59 的时间
endTime := time.Date(noticeEndDay.Year(), noticeEndDay.Month(), noticeEndDay.Day(), 23, 59, 59, 0, noticeEndDay.Location())
t.Logf("startTime:%s,endTime:%s", startTime, endTime)
}
func TestNum(t *testing.T) {
useNum := 0
used(&useNum)
t.Log(useNum)
}
func used(useNum *int) {
queryUsed(useNum)
queryUsed(useNum)
*useNum += 1
}
func queryUsed(useNum *int) {
*useNum += 1
}
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)
}
func TestLength(t *testing.T) {
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
}
}
}`
s := len(jsonStr)
t.Log(s)
var notify bo.WechatVoucherNotifyBo
err := json.Unmarshal([]byte(jsonStr), &notify)
if err != nil {
panic(err)
}
// 输出验证
fmt.Println("代金券ID", notify.PlainText.CouponID)
fmt.Println("核销金额(分):", notify.PlainText.ConsumeInformation.ConsumeAmount)
fmt.Println("核销时间:", notify.PlainText.ConsumeInformation.ConsumeTime)
fmt.Println("核销时间:", notify.PlainText.ConsumeInformation.ConsumeTime.Format(time.DateTime))
}