Home WeChat Applet WeChat Development Detailed explanation of refund steps for WeChat Pay

Detailed explanation of refund steps for WeChat Pay

Apr 27, 2017 pm 01:44 PM

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

1. Scan the WeChat QR code to log in

2. WeChat PC payment

It took a lot of trial and error 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 prompt for incorrect password 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 = "---";        //=======【证书路径设置】===================================== 
        /* 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要)        */
        public const string SSLCERT_PATH = "/WxPayAPI/cert/apiclient_cert.p12";        public const string SSLCERT_PASSWORD = "131xxxx";
Copy after login
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 the controller, including WeChat order number, merchant order number, total number 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);
        }
Copy after login

Run method of Refund class:

 /***
        * 申请退款完整业务流程逻辑
        * @param transaction_id 微信订单号(优先使用)
        * @param out_trade_no 商户订单号
        * @param total_fee 订单总金额
        * @param refund_fee 退款金额
        * @return 退款结果(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))//微信订单号存在的条件下,则已微信订单号为准            {
                data.SetValue("transaction_id", transaction_id);
            }            else//微信订单号不存在,才根据商户订单号去退款            {
                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);//操作员,默认为商户号
            WxPayData result = WxPayApi.Refund(data);//提交退款申请给API,接收返回数据
            Logger.Info("Refund process complete, result : " + result.ToXml());            return result.ToPrintStr();
        }
Copy after login

Refund: Method

 /**
        * 
        * 申请退款
        * @param WxPayData inputObj 提交给申请退款API的参数
        * @param int timeOut 超时时间
        * @throws WxPayException
        * @return 成功时返回接口调用结果,其他抛异常        */
        public static WxPayData Refund(WxPayData inputObj, int timeOut = 6)
        {            string url = "https://api.mch.weixin.qq.com/secapi/pay/refund";            //检测必填参数
            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("退款申请接口中,缺少必填参数out_refund_no!");
            }            else if (!inputObj.IsSet("total_fee"))
            {                throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
            }            else if (!inputObj.IsSet("refund_fee"))
            {                throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
            }            else if (!inputObj.IsSet("op_user_id"))
            {                throw new WxPayException("退款申请接口中,缺少必填参数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);//调用HTTP通信接口提交数据到API
            Log.Debug("WxPayApi", "Refund response : " + response);            var end = DateTime.Now;            int timeCost = (int)((end - start).TotalMilliseconds);//获得接口耗时            //将xml格式的结果转换为对象以返回
            WxPayData result = new WxPayData();
            result.FromXml(response);

            ReportCostTime(url, timeCost, result);//测速上报
            return result;
        }
Copy after login
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 processes are correct, this place is still very simple. WeChat’s regulations allow you to apply for refunds for transactions within one year. But there is another question, how to import the certificate into the virtual space, or do I need to change the cloud?

The above is the detailed content of Detailed explanation of refund steps 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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

If you forget your WeChat payment password, how to retrieve it? If you forget your WeChat payment password, how to retrieve it? Feb 23, 2024 pm 09:40 PM

In WeChat, users can enter their payment password to make purchases, but how do they retrieve their payment password if they forget it? Users need to go to My-Services-Wallet-Payment Settings-to recover their payment password if they forget it. This introduction to how to retrieve your payment password if you forget it will tell you the specific operation method. The following is a detailed introduction, so take a look! WeChat usage tutorial. How to find the WeChat payment password if you forget it? Answer: My-Service-Wallet-Payment Settings-Forgot payment password. Specific method: 1. First, click My. 2. Click on the service inside. 3. Click on the wallet inside. 4. Find the payment settings. 5. Click Forgot payment password. 6. Enter your own information for verification. 7. Then enter the new payment password to change it.

What should I do if I forget my WeChat payment password? What should I do if I forget my WeChat payment password? Jan 08, 2024 pm 05:02 PM

Solution for forgetting WeChat payment password: 1. Open WeChat APP, click "I" in the lower right corner to enter the personal center page; 2. In the personal center page, click "Pay" to enter the payment page; 3. On the payment page , click "..." in the upper right corner to enter the payment management page; 4. In the payment management page, find and click "Forgot payment password"; 5. Follow the page prompts and enter personal information for identity verification. After successful verification, you can Choose the method of "retrieve by swiping your face" or "retrieve by verifying bank card information" to retrieve your password, etc.

How to set up WeChat payment for Meituan Takeout How to set up WeChat payment How to set up WeChat payment for Meituan Takeout How to set up WeChat payment Mar 12, 2024 pm 10:34 PM

There are many food and snack shops provided in the Meituan takeout app, and all mobile phone users log in through their accounts. Add your personal delivery address and contact number to enjoy the most convenient takeout service. Open the homepage of the software, enter product keywords, and search online to find the corresponding product results. Just swipe up or down to purchase and place an order. The platform will also recommend dozens of nearby restaurants with high reviews based on the delivery address provided by the user. The store can also set up different payment methods. You can place an order with one click to complete the order. The rider can arrange the delivery immediately and the delivery speed is very fast. There are also takeout red envelopes of different amounts for use. Now the editor is online in detail for Meituan takeout users. We show you how to set up WeChat payment. 1. After selecting the product, submit the order and click Now

How to set the order of deduction for WeChat payment How to set the order of deduction for WeChat payment Sep 06, 2023 am 11:11 AM

Steps to set the order of deductions for WeChat payment: 1. Open the WeChat APP, click on the "Me" interface, click on "Services", and then click on "Collect and Payment"; 2. Click on "Prioritize Use This Payment Method" under the payment code on the collection and payment interface; 3. Select the preferred payment method you need.

Can Xianyu pay with WeChat? How to change to WeChat payment method? Can Xianyu pay with WeChat? How to change to WeChat payment method? Mar 12, 2024 pm 12:19 PM

When everyone has nothing to do, they will choose to browse the Xianyu platform. Everyone can find that there are a large number of products on this platform, which can allow everyone to see various second-hand products. Although these products are second-hand products, there is absolutely no problem with the quality of these products, so everyone can buy them with confidence. The prices are very affordable, and they still allow everyone to face-to-face with these products. It is entirely possible for sellers to communicate and conduct some price bargaining operations. As long as everyone negotiates properly, then you can choose to conduct transactions, and when everyone pays here, they want to make WeChat payment, but it seems that the platform It's not allowed. Please follow the editor to find out what the specific situation is. Xianyu

Can WeChat payment be canceled immediately after successful payment? Can WeChat payment be canceled immediately after successful payment? Nov 29, 2023 pm 02:19 PM

WeChat payment cannot be canceled immediately after successful payment. Refunds usually need to meet the following conditions: 1. The merchant's refund policy. The merchant will formulate its own refund policy, including the refund time window, refund amount and refund method; 2. Payment time, refunds usually require Apply within a certain time frame, and refunds may not be possible beyond this time frame; 3. Goods or service status. If the user has received the goods or enjoyed the service, the merchant may require the user to return the goods or provide corresponding proof; 4. Refund process, etc.

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.

How to pay with WeChat on Alibaba_How to pay with WeChat on Alibaba 1688 How to pay with WeChat on Alibaba_How to pay with WeChat on Alibaba 1688 Mar 20, 2024 pm 05:51 PM

Alibaba 1688 is a purchasing and wholesale website, and the items there are much cheaper than Taobao. So how does Alibaba use WeChat payment? The editor has compiled some relevant content to share with you. Friends in need can come and take a look. How does Alibaba use WeChat payment? Answer: WeChat payment cannot be used for the time being; 1. On the page where we purchase goods, we click [Change payment method] 2. Then in the pop-up page, we can only go to [Alipay, staged payment] , cashier] can be selected;

See all articles