微信红包发放调试
This commit is contained in:
parent
2160b6fc42
commit
3fc404807d
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
// main 这只是一个演示
|
||||
func main() {
|
||||
//wechatCpn()
|
||||
//alipayOrderRedPack()
|
||||
alipayQueryRedPack()
|
||||
//wechatRedPackOrder()
|
||||
wechatRedPackQuery()
|
||||
}
|
||||
|
|
|
@ -27,28 +27,24 @@ func getWechatRedPackConf() []byte {
|
|||
return marshal
|
||||
}
|
||||
|
||||
func wechatRedPack() {
|
||||
func wechatRedPackOrder() {
|
||||
err := manage.Add(wechatRedPackConf)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer manage.Close()
|
||||
wechatRedPackQuery()
|
||||
}
|
||||
|
||||
func wechatRedPackOrder() {
|
||||
req := &proto.OrderRequest{
|
||||
Config: getWechatRedPackConf(),
|
||||
Order: &proto.OrderRequest_Order{
|
||||
OrderNo: "240403164049635931",
|
||||
Account: "oO3vO5AxRWgTjmMD38FTvnB5Rq6o",
|
||||
OrderNo: "240403164049635934",
|
||||
Account: "olf756DZlPHhTAduH9213h6Z2PCU",
|
||||
Amount: 0.01,
|
||||
Quantity: 1,
|
||||
Extra: []byte(`{"app_id":"wxbfcf9fd93f390c3a", "out_detail_no":"123456789"}`),
|
||||
Extra: []byte(`{"app_id":"wx381e6a04ab7f69b6", "out_detail_no":"12345678912"}`),
|
||||
},
|
||||
Product: &proto.OrderRequest_Product{
|
||||
ProductNo: "",
|
||||
Extra: []byte(`{"batch_name":"13100720242", "batch_remark":"stock_creator_mchid"}`),
|
||||
Extra: []byte(`{"batch_name":"batch_name", "batch_remark":"batch_remark"}`),
|
||||
},
|
||||
}
|
||||
res, err := instance.Order(context.Background(), wechatRedPackConf.Tag, req)
|
||||
|
@ -59,14 +55,19 @@ func wechatRedPackOrder() {
|
|||
}
|
||||
|
||||
func wechatRedPackQuery() {
|
||||
err := manage.Add(wechatRedPackConf)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer manage.Close()
|
||||
//{status:ING order_no:"240403164049635931" trade_no:"131000508038701499912952024090256259261117" message:"成功"}
|
||||
queryRequest := &proto.QueryRequest{
|
||||
Config: getWechatRedPackConf(),
|
||||
Order: &proto.QueryRequest_Order{
|
||||
OrderNo: "202409141056275034200011",
|
||||
OrderNo: "240403164049635934",
|
||||
TradeNo: "",
|
||||
Account: "",
|
||||
Extra: []byte(`{"out_detail_no":"0a2511525cc94a27bac18328771dc53e"}`),
|
||||
Extra: []byte(`{"out_detail_no":"12345678912"}`),
|
||||
},
|
||||
}
|
||||
resQuery, err := instance.Query(context.Background(), wechatRedPackConf.Tag, queryRequest)
|
||||
|
|
|
@ -40,17 +40,19 @@ func orderReq(order *proto.OrderRequest_Order, product *proto.OrderRequest_Produ
|
|||
if err != nil {
|
||||
return transferbatch.InitiateBatchTransferRequest{}, fmt.Errorf("product拓展参数json unmarshal error:[%+v], extra[%s]", err, string(product.Extra))
|
||||
}
|
||||
transferAmount := int64(order.Amount * 100)
|
||||
fmt.Println("transferAmount", transferAmount)
|
||||
return transferbatch.InitiateBatchTransferRequest{
|
||||
Appid: core.String(orderExtra.Appid),
|
||||
OutBatchNo: core.String(order.OrderNo), // 微信转账商家批次单号
|
||||
BatchName: core.String(productExtra.BatchName),
|
||||
BatchRemark: core.String(productExtra.BatchRemark),
|
||||
TotalAmount: core.Int64(int64(order.Amount * 100)), // 转账总金额,单位分 100=1元 1000=0.1(需要申请)
|
||||
TotalAmount: core.Int64(transferAmount), // 转账总金额,单位分 100=1元 1000=0.1(需要申请)
|
||||
TotalNum: core.Int64(int64(order.Quantity)),
|
||||
TransferDetailList: []transferbatch.TransferDetailInput{
|
||||
{
|
||||
OutDetailNo: core.String(orderExtra.OutDetailNo),
|
||||
TransferAmount: core.Int64(int64(order.Amount * 100)),
|
||||
TransferAmount: core.Int64(transferAmount),
|
||||
TransferRemark: core.String(productExtra.BatchRemark),
|
||||
Openid: core.String(order.Account),
|
||||
UserName: nil,
|
||||
|
@ -91,12 +93,12 @@ func queryResp(request *proto.QueryRequest, resp *transferbatch.TransferDetailEn
|
|||
data, _ := resp.MarshalJSON()
|
||||
status := vo.QueryStatus(*resp.DetailStatus)
|
||||
msg := status.GetText()
|
||||
if resp.FailReason.Ptr() != nil {
|
||||
m, ok := vo.FailReasonMsg[*resp.FailReason.Ptr()]
|
||||
if resp.FailReason != nil {
|
||||
m, ok := vo.FailReasonMsg[*resp.FailReason]
|
||||
if ok {
|
||||
msg = fmt.Sprintf("Message:%s, FailReason:%s", msg, m)
|
||||
} else {
|
||||
msg = fmt.Sprintf("Message:%s, FailReason:%s", msg, *resp.FailReason.Ptr())
|
||||
msg = fmt.Sprintf("Message:%s, FailReason:%s", msg, *resp.FailReason)
|
||||
}
|
||||
}
|
||||
return &proto.QueryResponse{
|
||||
|
|
|
@ -15,6 +15,7 @@ const (
|
|||
CookieValue = "wechat_redpack"
|
||||
)
|
||||
|
||||
// WeChatRedPackService @link https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-batch/initiate-batch-transfer.html
|
||||
type WeChatRedPackService struct{}
|
||||
|
||||
func (p *WeChatRedPackService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
||||
|
|
Loading…
Reference in New Issue