国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home WeChat Applet WeChat Development Development of refund function for WeChat Pay

Development of refund function for WeChat Pay

Mar 16, 2018 pm 01:42 PM
Function develop Refund

This time I will bring you the development of the refund function of WeChat payment. What are the precautions for the development of the refund function of WeChat payment. The following is a practical case, let's take a look.

Let’s first complain about WeChat’s documentation and demo. The important step information is not emphasized clearly, and the .net demo has never been successfully run.

1. Scan the WeChat QR code to log in

2. WeChat PC payment

It took several attempts to get through this refund function. The following introduces the development steps of the WeChat payment refund function:

1. Download the certificate and import it into the system

WeChat refund requires a certificate. This certificate is not the certificate in the official demo, but You need to download the certificate from the api security column in the WeChat merchant platform. In a word document of the official certificate usage example, you can see the following words: C# There is one thing to note, in addition to using ## in the code In addition to #apiclient_cert.p12, the certificate also needs to be imported into the operating system before it can be used. 1. Used in the code; 2. Imported into the operating system, both of which are indispensable. .NET version needs to be greater than 2.0 I didn’t know these two steps before and wasted too much time. So download the certificate first:

# When downloading, you need mobile phone verification and login password. After downloading, find the certificate

apiclient_cert.p12 and double-click to import it. When importing, you will be prompted to enter a password. This password is the merchant ID, and it must be the certificate downloaded on your own merchant platform. Otherwise, a password error prompt will appear:

Import the correct prompt:

2. Code Refund

You can directly use the code in the official demo here. To download the demo, you need to modify several parameters in WxPayConfig:

?   ??public?const?string?APPID?=?"wxf6dd794bcexxxx";????????public?const?string?MCHID?=?"xxxx";????????public?const?string?KEY?=?"xxxxx849ba56abbe56e05xxxxx";????????public?const?string?APPSECRET?=?"---";????????//=======【證書路徑設(shè)置】=====================================?
????????/*?證書路徑,注意應(yīng)該填寫絕對路徑(僅退款、撤銷訂單時需要)????????*/
????????public?const?string?SSLCERT_PATH?=?"/WxPayAPI/cert/apiclient_cert.p12";????????public?const?string?SSLCERT_PASSWORD?=?"131xxxx";
The SSLCERT_PASSWORD above is MCHID, which is the merchant ID. SSLCERT_PASSWORD error will prompt that the specified network password is incorrect:

Next, add a refund method in controller

, including the WeChat order number , merchant order number, total amount and refund amount. Choose one of the merchant order number and WeChat order number. Detailed parameters

??public?ActionResult?DoRefund()
????????{????????????string?result?=?Refund.Run("","131667780120trade_no",?"1",?"1");????????????return?Content(result);
????????}
Run method of Refund class:
?/***
????????*?申請退款完整業(yè)務(wù)流程邏輯
????????*?@param?transaction_id?微信訂單號(優(yōu)先使用)
????????*?@param?out_trade_no?商戶訂單號
????????*?@param?total_fee?訂單總金額
????????*?@param?refund_fee?退款金額
????????*?@return?退款結(jié)果(xml格式)????????*/
????????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_id))//微信訂單號存在的條件下,則已微信訂單號為準(zhǔn)????????????{
????????????????data.SetValue("transaction_id",?transaction_id);
????????????}????????????else//微信訂單號不存在,才根據(jù)商戶訂單號去退款????????????{
????????????????data.SetValue("out_trade_no",?out_trade_no);
????????????}
????????????data.SetValue("total_fee",?int.Parse(total_fee));//訂單總金額
????????????data.SetValue("refund_fee",?int.Parse(refund_fee));//退款金額
????????????data.SetValue("out_refund_no",?out_trade_no);//隨機生成商戶退款單號
????????????data.SetValue("op_user_id",?WxPayConfig.MCHID);//操作員,默認(rèn)為商戶號
????????????WxPayData?result?=?WxPayApi.Refund(data);//提交退款申請給API,接收返回數(shù)據(jù)
????????????Logger.Info("Refund?process?complete,?result?:?"?+?result.ToXml());????????????return?result.ToPrintStr();
????????}
Refund: Method

?/**
????????*?
????????*?申請退款
????????*?@param?WxPayData?inputObj?提交給申請退款A(yù)PI的參數(shù)
????????*?@param?int?timeOut?超時時間
????????*?@throws?WxPayException
????????*?@return?成功時返回接口調(diào)用結(jié)果,其他拋異常????????*/
????????public?static?WxPayData?Refund(WxPayData?inputObj,?int?timeOut?=?6)
????????{????????????string?url?=?"https://api.mch.weixin.qq.com/secapi/pay/refund";????????????//檢測必填參數(shù)
????????????if?(!inputObj.IsSet("out_trade_no")?&&?!inputObj.IsSet("transaction_id"))
????????????{????????????????throw?new?WxPayException("退款申請接口中,out_trade_no、transaction_id至少填一個!");
????????????}????????????else?if?(!inputObj.IsSet("out_refund_no"))
????????????{????????????????throw?new?WxPayException("退款申請接口中,缺少必填參數(shù)out_refund_no!");
????????????}????????????else?if?(!inputObj.IsSet("total_fee"))
????????????{????????????????throw?new?WxPayException("退款申請接口中,缺少必填參數(shù)total_fee!");
????????????}????????????else?if?(!inputObj.IsSet("refund_fee"))
????????????{????????????????throw?new?WxPayException("退款申請接口中,缺少必填參數(shù)refund_fee!");
????????????}????????????else?if?(!inputObj.IsSet("op_user_id"))
????????????{????????????????throw?new?WxPayException("退款申請接口中,缺少必填參數(shù)op_user_id!");
????????????}
????????????inputObj.SetValue("appid",?WxPayConfig.APPID);//公眾賬號ID
????????????inputObj.SetValue("mch_id",?WxPayConfig.MCHID);//商戶號
????????????inputObj.SetValue("nonce_str",?Guid.NewGuid().ToString().Replace("-",?""));//隨機字符串
????????????inputObj.SetValue("sign",?inputObj.MakeSign());//簽名
????????????
????????????string?xml?=?inputObj.ToXml();????????????var?start?=?DateTime.Now;
????????????Log.Debug("WxPayApi",?"Refund?request?:?"?+?xml);????????????string?response?=?HttpService.Post(xml,?url,?true,?timeOut);//調(diào)用HTTP通信接口提交數(shù)據(jù)到API
????????????Log.Debug("WxPayApi",?"Refund?response?:?"?+?response);????????????var?end?=?DateTime.Now;????????????int?timeCost?=?(int)((end?-?start).TotalMilliseconds);//獲得接口耗時????????????//將xml格式的結(jié)果轉(zhuǎn)換為對象以返回
????????????WxPayData?result?=?new?WxPayData();
????????????result.FromXml(response);
????????????ReportCostTime(url,?timeCost,?result);//測速上報
????????????return?result;
????????}
Remember to modify it to your own parameters in the production environment. If the parameters are correct, it will return:

Moreover, WeChat will immediately receive a refund notification:

Summary : At this point, the refund function has been implemented. In fact, if the parameters and process are correct, this place is still very simple. WeChat’s regulations allow you to apply for refunds for transactions within one year.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to use the gradient of ss3


Detailed explanation of Promise in jQuery, Angular and node


H5 video playback library video.js detailed explanation

The above is the detailed content of Development of refund function for WeChat Pay. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

What exactly is self-media? What are its main features and functions? What exactly is self-media? What are its main features and functions? Mar 21, 2024 pm 08:21 PM

With the rapid development of the Internet, the concept of self-media has become deeply rooted in people's hearts. So, what exactly is self-media? What are its main features and functions? Next, we will explore these issues one by one. 1. What exactly is self-media? We-media, as the name suggests, means you are the media. It refers to an information carrier through which individuals or teams can independently create, edit, publish and disseminate content through the Internet platform. Different from traditional media, such as newspapers, television, radio, etc., self-media is more interactive and personalized, allowing everyone to become a producer and disseminator of information. 2. What are the main features and functions of self-media? 1. Low threshold: The rise of self-media has lowered the threshold for entering the media industry. Cumbersome equipment and professional teams are no longer needed.

The difference between vivox100s and x100: performance comparison and function analysis The difference between vivox100s and x100: performance comparison and function analysis Mar 23, 2024 pm 10:27 PM

Both vivox100s and x100 mobile phones are representative models in vivo's mobile phone product line. They respectively represent vivo's high-end technology level in different time periods. Therefore, the two mobile phones have certain differences in design, performance and functions. This article will conduct a detailed comparison between these two mobile phones in terms of performance comparison and function analysis to help consumers better choose the mobile phone that suits them. First, let’s look at the performance comparison between vivox100s and x100. vivox100s is equipped with the latest

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Sharing the steps to apply for a refund with WeChat Pay Sharing the steps to apply for a refund with WeChat Pay Mar 25, 2024 pm 06:31 PM

1. First, we need to open the WeChat APP on the mobile phone, and then click to log in to the WeChat account, so that we enter the WeChat homepage. 2. Click the [Me] button in the lower right corner of the WeChat homepage, then select the [Payment] option. We click to enter the payment page. 3. After entering the [Payment] page, click the [Wallet] option to enter, and click [Bill] in the upper right corner of the [Wallet] page.

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

How long does it take for the Doudian deposit to be refunded? How long does it take for the refund to arrive? How long does it take for the Doudian deposit to be refunded? How long does it take for the refund to arrive? Mar 26, 2024 pm 01:56 PM

With the popularity of the Internet, online shopping has become an important part of people's lives. Douyin’s Douyin store has attracted a large number of users with its unique sales model and diverse products. However, during the shopping process, some users were confused about Doudian’s deposit return policy. As consumers pay more attention to shopping safety and rights, Doudian needs a more transparent and standardized refund mechanism to build consumer trust. By optimizing the refund process and strengthening supervision of merchants, Doudian can improve user experience and increase user loyalty. Consumers can also pay attention to platform regulations and communicate with merchants to effectively solve the deposit refund problem and ensure that their own rights and interests are not harmed. 1. How long does it take for the Doudian deposit to be refunded? Doudian is a shopping model based on a credit system, which requires consumers to

How to cancel a hotel reservation on Ctrip How to cancel a hotel reservation on Ctrip Apr 01, 2024 pm 07:34 PM

Ctrip brings together millions of hotels, airlines, car rental companies and travel service providers around the world to provide users with a wide variety of travel options. Today I am going to talk about one of the Ctrip travel hotel check-out tutorials. If you need it, learn together. Get off. The first step of the Ctrip hotel check-out process is to enter the Ctrip APP, select [Itinerary] below, and then click [Order Details] of the hotel we have booked. Step 2: Click [Cancel Order] in the lower left corner. Step 3: Click on the reason for cancellation, and then click [Cancel Order] at the bottom.

See all articles