WeChat payment SDK for Golang

Source: Internet
Author: User

A payment SDK that is tailor-made for go language and is super-useful.

GitHub Address: Wxpay

Payment Development Documentation API

The APIs that are given in the payment developer documentation are encapsulated.

The Wxpay provides the corresponding method:

| Method name | Description |

| ---------------- | ----------- |

| Micropay | Credit Card Payment |

| Unifiedorder | Unified Order |

| Orderquery | Order Enquiry |

| Reverse | Cancel Order |

| Closeorder | Close Order |

| Refund | Request a Refund |

| Refundquery | Request a Refund |

| Downloadbill | Download the statement |

| Report | Transaction Protection |

| Shorturl | Convert Short Links |

| Authcodetoopenid | Authorization Code Query OpenID |

    • The parameter is Params a type, and the return type Params is also Params a struct of type map[string]string.

    • The method internally converts the parameters into XML containing appid ,,, mch_id nonce_str sign\_type and sign ;

    • The default is to use MD5 to sign;

    • The data returned by the HTTPS request is processed as necessary (such as verifying the signature, and the signature error throws an exception).

    • For Downloadbill, either the success or not is returned to map, and both contain return_code and return_msg . If successful, which return_code is SUCCESS , in addition data corresponds to the statement data.

Installation

go get github.com/objcoding/wxpay

Example

 //new Payment client clients: = Wxpay. Newclient (Wxpay. Newaccount{appid: "AppID", Mchid: "Mchid", ApiKey: "ApiKey",}, False)//sandbox environment please pass true//Unified next single params: = Make (Wxpay. params) params. SetString ("Body", "test"). SetString ("Out_trade_no", "436577857"). SetInt64 ("Total_fee", 1). SetString ("Spbill_create_ip", "127.0.0.1"). SetString ("Notify_url", "http://notify.objcoding.com/notify"). SetString ("Trade_type", "APP") p, _: = client. Unifiedorder (params)//order query params: = Make (Wxpay. params) params. SetString ("Out_trade_no", "3568785") p, _: = client. Orderquery (params)//refund Params: = Make (Wxpay. params) params. SetString ("Out_trade_no", "3568785"). SetString ("Out_refund_no", "19374568"). SetInt64 ("Total_fee", 1). SetInt64 ("Refund_fee", 1) p, _: = client. Refund (params)//refund query params: = Make (Wxpay. params) params. SetString ("Out_refund_no", "3568785") p, _: = client. Refundquery (params)  
// 创建支付账户account := wxpay.NewAccount("appid", "mchid", "apiKey")// 设置证书account.SetCertData("证书地址")// 新建支付客户端client := wxpay.NewClient(account, false) // sandbox环境请传true// 设置http请求超时时间client.SetHttpConnectTimeoutMs(2000)// 设置http读取信息流超时时间client.SetHttpReadTimeoutMs(1000)// 更改签名类型client.SetSignType(HMACSHA256)// 设置支付账户client.setAccount(account)
// 签名signStr := client.Sign(params)// 校验签名b := client.ValidSign(params)
// 支付或退款返回成功信息return wxpay.Notifies{}.OK()// 支付或退款返回失败信息return wxpay.Notifies{}.NotOK("支付失败或退款失败了")

License

MIT License

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.