In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to achieve WeChat Pay's refund function". The content is simple and clear. I hope it can help you solve your doubts. Next, let the editor lead you to study and learn "how to achieve WeChat Pay's refund function" this article.
Download the certificate and import it into the system
Wechat refund requires a certificate. This certificate is not a certificate in the official demo, but a certificate downloaded by yourself in the api security bar of Wechat merchant platform. See the following words in an word document of an official certificate usage example: C # need to note that in addition to using apiclient_cert.p12 in the code, you also need to import the certificate into the operating system to use, 1, use in the code, 2. Import the operating system, both of which are indispensable. I didn't know these two steps before the .NET version needed to be greater than 2.0, which wasted too much time. So download the certificate first:
Mobile phone authentication and login password are required when downloading. After downloading, find the apiclient_cert.p12 certificate, double-click to import, and prompt for the password, which is the merchant ID and must be the certificate downloaded on your merchant platform. Otherwise, an incorrect password will appear:
Import the correct prompt:
Code refund
This place can be downloaded directly with the code in the official demo, demo.
Several parameters in WxPayConfig need to be modified:
Public const string APPID = "wxf6dd794bcexxxx"; public const string MCHID = "xxxx"; public const string KEY = "xxxxx849ba56abbe56e05xxxxx"; public const string APPSECRET = "- -" / / = [Certificate path setting] = / * Certificate path. Note that absolute path should be entered (only required for refund or cancellation of order) * / public const string SSLCERT_PATH = "/ WxPayAPI/cert/apiclient_cert.p12"; public const string SSLCERT_PASSWORD = "131xxxx"
The above SSLCERT_PASSWORD is MCHID, that is, an incorrect network password will appear when the merchant makes an ID,SSLCERT_PASSWORD error:
Next, add a refund method to the controller, including Wechat order number, merchant order number, total amount and refund amount. The merchant order number and Wechat order number choose one of the two. Detailed parameters
Public ActionResult DoRefund () {string result = Refund.Run ("", "131667780120trade_no", "1", "1"); return Content (result);}
The Run method of the Refund class:
/ * complete business process logic for refund application * @ param transaction_id Wechat order number (priority) * @ param out_trade_no merchant order number * @ param total_fee order total amount * @ param refund_fee refund amount * @ return refund result * / public static string Run (string transaction_id) String out_trade_no, string total_fee, string refund_fee) {Logger.Info ("Refund is processing...") WxPayData data = new WxPayData (); if (! string.IsNullOrEmpty (transaction new WxPayData / / Wechat order number exists, then Wechat order number is {data.SetValue ("transaction_id", transaction_id) } else// Wechat order number does not exist, so refund {data.SetValue ("out_trade_no", out_trade_no);} data.SetValue ("total_fee", int.Parse (total_fee)) according to the merchant order number / / Total order amount data.SetValue ("refund_fee", int.Parse (refund_fee)); / / refund amount data.SetValue ("out_refund_no", out_trade_no); / / randomly generated merchant refund order number data.SetValue ("op_user_id", WxPayConfig.MCHID); / / operator. Default is merchant number WxPayData result = WxPayApi.Refund (data). / / submit a refund request to API and receive the returned data Logger.Info ("Refund process complete, result:" + result.ToXml ()); return result.ToPrintStr ();}
Refund: method
/ * * apply for refund * @ param WxPayData inputObj the parameter submitted to the refund API * @ param int timeOut timeout * @ throws WxPayException * @ return returns the result of API call if successful Other exceptions thrown * / public static WxPayData Refund (WxPayData inputObj, int timeOut = 6) {string url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; / / check the required parameter if (! inputObj.IsSet ("out_trade_no") & &! inputObj.IsSet ("transaction_id") {throw new WxPayException ("at least one out_trade_no or transaction_id in the refund application API!") ;} else if (! inputObj.IsSet ("out_refund_no")) {throw new WxPayException ("the required parameter out_refund_no! is missing in the refund application API") ;} else if (! inputObj.IsSet ("total_fee")) {throw new WxPayException ("the required parameter total_fee! is missing in the refund application API") ;} else if (! inputObj.IsSet ("refund_fee")) {throw new WxPayException ("the required parameter refund_fee! is missing in the refund application API") ;} else if (! inputObj.IsSet ("op_user_id")) {throw new WxPayException ("the required parameter op_user_id! is missing in the refund application API") ;} inputObj.SetValue ("appid", WxPayConfig.APPID); / / Public account ID inputObj.SetValue ("mch_id", WxPayConfig.MCHID); / / merchant ID inputObj.SetValue ("nonce_str", Guid.NewGuid (). ToString (). Replace ("-", ")); / / Random string inputObj.SetValue (" sign ", inputObj.MakeSign ()) / / sign string xml = inputObj.ToXml (); var start = DateTime.Now; Log.Debug ("WxPayApi", "Refund request:" + xml); string response = HttpService.Post (xml, url, true, timeOut); / / call HTTP communication interface to submit data to API Log.Debug ("WxPayApi", "Refund response:" + response) Var end = DateTime.Now; int timeCost = (int) ((end-start) .TotalMilliseconds); / / it takes time to get the API / / convert the result in xml format to an object to return WxPayData result = new WxPayData (); result.FromXml (response); ReportCostTime (url, timeCost, result); / / Speed report return result;}
Remember to change it to your own parameters in the production environment. If all the parameters are correct, it will return:
In addition, Wechat immediately received a refund notice:
The above is all the contents of the article "how to achieve WeChat Pay's refund function". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 227
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.