|
@@ -142,3 +142,114 @@ func WxDecodeNotify(body []byte) (wechatPayCallback *WechatPayCallback) {
|
|
wechatPayCallback = datamap
|
|
wechatPayCallback = datamap
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// Transaction
|
|
|
|
+type Transaction struct {
|
|
|
|
+ Amount TransactionAmount `json:"amount,omitempty"`
|
|
|
|
+ Appid string `json:"appid,omitempty"`
|
|
|
|
+ Attach string `json:"attach,omitempty"`
|
|
|
|
+ BankType string `json:"bank_type,omitempty"`
|
|
|
|
+ Mchid string `json:"mchid,omitempty"`
|
|
|
|
+ OutTradeNo string `json:"out_trade_no,omitempty"`
|
|
|
|
+ Payer TransactionPayer `json:"payer,omitempty"`
|
|
|
|
+ PromotionDetail []PromotionDetail `json:"promotion_detail,omitempty"`
|
|
|
|
+ SuccessTime time.Time `json:"success_time,omitempty"`
|
|
|
|
+ TradeState string `json:"trade_state,omitempty"`
|
|
|
|
+ TradeStateDesc string `json:"trade_state_desc,omitempty"`
|
|
|
|
+ TradeType string `json:"trade_type,omitempty"`
|
|
|
|
+ TransactionId string `json:"transaction_id,omitempty"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// TransactionAmount
|
|
|
|
+type TransactionAmount struct {
|
|
|
|
+ Currency string `json:"currency,omitempty"`
|
|
|
|
+ PayerCurrency string `json:"payer_currency,omitempty"`
|
|
|
|
+ PayerTotal int64 `json:"payer_total,omitempty"`
|
|
|
|
+ Total int64 `json:"total,omitempty"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// PromotionDetail
|
|
|
|
+type PromotionDetail struct {
|
|
|
|
+ // 券ID
|
|
|
|
+ CouponId *string `json:"coupon_id,omitempty"`
|
|
|
|
+ // 优惠名称
|
|
|
|
+ Name *string `json:"name,omitempty"`
|
|
|
|
+ // GLOBAL:全场代金券;SINGLE:单品优惠
|
|
|
|
+ Scope *string `json:"scope,omitempty"`
|
|
|
|
+ // CASH:充值;NOCASH:预充值。
|
|
|
|
+ Type *string `json:"type,omitempty"`
|
|
|
|
+ // 优惠券面额
|
|
|
|
+ Amount *int64 `json:"amount,omitempty"`
|
|
|
|
+ // 活动ID,批次ID
|
|
|
|
+ StockId *string `json:"stock_id,omitempty"`
|
|
|
|
+ // 单位为分
|
|
|
|
+ WechatpayContribute *int64 `json:"wechatpay_contribute,omitempty"`
|
|
|
|
+ // 单位为分
|
|
|
|
+ MerchantContribute *int64 `json:"merchant_contribute,omitempty"`
|
|
|
|
+ // 单位为分
|
|
|
|
+ OtherContribute *int64 `json:"other_contribute,omitempty"`
|
|
|
|
+ // CNY:人民币,境内商户号仅支持人民币。
|
|
|
|
+ Currency *string `json:"currency,omitempty"`
|
|
|
|
+ GoodsDetail []PromotionGoodsDetail `json:"goods_detail,omitempty"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// PromotionGoodsDetail
|
|
|
|
+type PromotionGoodsDetail struct {
|
|
|
|
+ // 商品编码
|
|
|
|
+ GoodsId *string `json:"goods_id"`
|
|
|
|
+ // 商品数量
|
|
|
|
+ Quantity *int64 `json:"quantity"`
|
|
|
|
+ // 商品价格
|
|
|
|
+ UnitPrice *int64 `json:"unit_price"`
|
|
|
|
+ // 商品优惠金额
|
|
|
|
+ DiscountAmount *int64 `json:"discount_amount"`
|
|
|
|
+ // 商品备注
|
|
|
|
+ GoodsRemark *string `json:"goods_remark,omitempty"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// TransactionPayer
|
|
|
|
+type TransactionPayer struct {
|
|
|
|
+ Openid string `json:"openid,omitempty"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 根据订单号查询订单状态
|
|
|
|
+func GetQueryOrderByOutTradeNo(outTradeNo string) (tradeState string, statusCode int, itemResp *Transaction) {
|
|
|
|
+ var err error
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("err", err)
|
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint("根据订单号查询订单状态 失败 GetQueryOrderByOutTradeNo, err:", err.Error(), "outTradeNo", outTradeNo), 2)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ ctx := context.Background()
|
|
|
|
+ svc := jsapi.JsapiApiService{Client: utils.WechatCertClient}
|
|
|
|
+ resp, result, err := svc.QueryOrderByOutTradeNo(ctx,
|
|
|
|
+ jsapi.QueryOrderByOutTradeNoRequest{
|
|
|
|
+ OutTradeNo: core.String(outTradeNo),
|
|
|
|
+ Mchid: core.String(utils.Mchid),
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+ statusCode = result.Response.StatusCode
|
|
|
|
+
|
|
|
|
+ //订单状态码不存在直接返回
|
|
|
|
+ if statusCode == 404 {
|
|
|
|
+ err = nil
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ tradeState = *resp.TradeState
|
|
|
|
+ data, err := json.Marshal(resp)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ jsonstr := string(data)
|
|
|
|
+ //item := new(Transaction)
|
|
|
|
+ if err = json.Unmarshal([]byte(jsonstr), &itemResp); err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ //utils.FileLog.Info(jsonstr)
|
|
|
|
+ ////itemResp = item
|
|
|
|
+ //fmt.Println(itemResp)
|
|
|
|
+ //fmt.Println(tradeState)
|
|
|
|
+ //fmt.Println(itemResp.TransactionId)
|
|
|
|
+ return
|
|
|
|
+}
|