WeChat payment official SDK for Golang

Source: Internet
Author: User
# Wxpay for Golang Note: I pay the official SDK Java version, with the Go language implementation of a payment SDK, with the Java version of the features, with a light-weight easy to use, and full-featured features, theoretical performance will be faster than the Java version. GitHub address: [Wxpay] (Https://github.com/objcoding/wxpay) # # Payment Development Documentation API to [payment Developer documentation] (https://pay.weixin.qq.com/wiki/doc/ api/index.html) is encapsulated in the APIs given in. 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 link | | Authcodetoopenid | Authorization code Query OpenID |* parameter is ' params ' type, return type is ' params ', ' params ' is a struct of map[string]string type. * The method internally will convert the parameters into a xml;* with ' AppID ', ' mch_id ', ' nonce_str ', ' sign\_type ' and ' sign ', using MD5 as the default signature; 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, whether or not the success of the return map, and all contain ' return_code ' and ' return_msg '. If successful, where ' Return_code ' is ' SUCCESS ', the other ' data ' corresponds to the billing data. # # Install ' Go get Github.com/objcoding/wxpay ' ' # # example '//new Payment client: = 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) '//Create Payment Account: = Wxpay. NewAccount ("AppID", "Mchid", "ApiKey")//Set the certificate account. Setcertdata ("certificate Address")//New Payment client: = Wxpay. Newclient (account, false)//sandbox environment please pass true//set HTTP request Timeout time client. SETHTTPCONNECTTIMEOUTMS (2000)//set HTTP read stream timeout time client. SETHTTPREADTIMEOUTMS (1000)//change signature type client. Setsigntype (HMACSHA256)//Set up payment accounts client.setaccount (account) "" "//Signature Signstr: = client. sign (params)//check signature b: = client. Validsign (params) ""//Payment or Refund Returns success information return Wxpay. notifies{}. OK ()//payment or refund returns the failure information return Wxpay. notifies{}. Notok ("Payment failed or refund failed") ' # # Licensemit license199 times  ∙  1 likes  
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.