123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package services
- import (
- "context"
- "encoding/json"
- "fmt"
- "github.com/wechatpay-apiv3/wechatpay-go/core"
- "github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
- "hongze/hongze_cygx/utils"
- "time"
- )
- 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)
-
- if err = json.Unmarshal([]byte(jsonstr), &itemResp); err != nil {
- return
- }
-
-
-
-
- return
- }
- func ExampleJsapiApiService_CloseOrder(OutTradeNo string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("订单超时手动关闭订单 失败 ExampleJsapiApiService_CloseOrder, err:", err.Error(), "OrderCode:", OutTradeNo), 2)
- }
- }()
- ctx := context.Background()
- svc := jsapi.JsapiApiService{Client: utils.WechatCertClient}
- _, err = svc.CloseOrder(ctx,
- jsapi.CloseOrderRequest{
- OutTradeNo: core.String(OutTradeNo),
- Mchid: core.String(utils.Mchid),
- },
- )
- return
- }
- 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"`
- }
- 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"`
- }
- type TransactionPayer struct {
- Openid string `json:"openid,omitempty"`
- }
- type PromotionDetail struct {
-
- CouponId *string `json:"coupon_id,omitempty"`
-
- Name *string `json:"name,omitempty"`
-
- Scope *string `json:"scope,omitempty"`
-
- Type *string `json:"type,omitempty"`
-
- Amount *int64 `json:"amount,omitempty"`
-
- StockId *string `json:"stock_id,omitempty"`
-
- WechatpayContribute *int64 `json:"wechatpay_contribute,omitempty"`
-
- MerchantContribute *int64 `json:"merchant_contribute,omitempty"`
-
- OtherContribute *int64 `json:"other_contribute,omitempty"`
-
- Currency *string `json:"currency,omitempty"`
- GoodsDetail []PromotionGoodsDetail `json:"goods_detail,omitempty"`
- }
- 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"`
- }
|