Activation of enterprise transfer to user interface
This time I will bring you the activation of the enterprise transfer to user interface. What are the precautions for the activation of enterprise transfer to user interface? The following is a practical case, let's take a look.
There is no such interface in the WeChat public account payment API. If the enterprise needs totransfer money to the user, or allow the user to withdraw cash or send red envelope# to the user ## etc. need to be activated separately in the product center in the merchant platform. 1. Activating the function
#Activating is just one click, very simple. However, it should be noted that the account that supports transfers to users and the account that receives payments from users are not the same. In order to meet this function, you need to recharge with Tenpay first (
). 2. Download the certificate
The certificate is downloaded in the Account Center-API Security. Now you need the mobile phone
verification codeand the merchant platform login password. After downloading, install it on Windows. The password for installation is your merchant number.
#After installation, place the certificate in the website directory for verification in the code in the next step.
3. Transfer
The demo currently provided by WeChat does not include this part. Let’s make some modifications based on the official demo. Similar to the previous example, we all need to use the WxPayData object to manipulate our parameters. Define a TransfersPay object.
public class TransfersPay { public string openid { get; set; } public int amount { get; set; } public string partner_trade_no { get; set; } public string re_user_name { get; set; } public string spbill_create_ip { get; set; } public WxPayData GetTransfersApiParameters() { WxPayData apiParam = new WxPayData(); apiParam.SetValue("partner_trade_no", partner_trade_no); apiParam.SetValue("openid", openid); apiParam.SetValue("check_name", "NO_CHECK"); apiParam.SetValue("amount", amount); apiParam.SetValue("desc", "提现"); apiParam.SetValue("spbill_create_ip", spbill_create_ip); apiParam.SetValue("re_user_name", re_user_name); return apiParam; } }
The WxpayApi in the official demo already contains methods related to official account payment. Add another Transfers method to transfer money:
public static WxPayData Transfers(WxPayData inputData, int timeOut = 6) { var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; inputData.SetValue("mch_appid", WxPayConfig.APPID);//公众账号ID inputData.SetValue("mchid", WxPayConfig.MCHID);//商户号 inputData.SetValue("nonce_str", WxPayApi.GenerateNonceStr());//随机字符串 inputData.SetValue("sign", inputData.MakeSign());//签名 string xml = inputData.ToXml(); var start = DateTime.Now; string response = HttpService.Post(xml, url, true, timeOut); // Portal.MVC.Logger.Info("WxPayApi"+ "UnfiedOrder response : " + response); var end = DateTime.Now; int timeCost = (int)((end - start).TotalMilliseconds); WxPayData result = new WxPayData(); result.FromXml(response); ReportCostTime(url, timeCost, result);//测速上报 return result; }
Something that needs a little attention is that the names of several default parameters are different from other methods, such as appid and mch_id. In the transfer, they are mch_appid and mchid, and in the red envelope, they are also called wxappid and mch_id. Then notice that the third parameter of the httpService.post method is true. That is, the certificate will be used. Entering the post method, we can see:
//是否使用证书 if (isUseCert) { string path = HttpContext.Current.Request.PhysicalApplicationPath; X509Certificate2 cert = new X509Certificate2(path + WxPayConfig.SSLCERT_PATH, WxPayConfig.SSLCERT_PASSWORD); request.ClientCertificates.Add(cert); Log.Debug("WxPayApi", "PostXml used cert"); }
The path and password of the certificate are used here, and the password is the merchant number. After everything is ready, you can transfer money in the controller:
[LoginValid] public ActionResult CashTransfers(string orderNumber) { //var order = new Order(){Amount = 1}; // var openid = "oBSBmwQjqwjfzQlKsFNjxFLSixxx"; var user = _workContext.CurrentUser; var order = _paymentService.GetOrderByOrderNumber(orderNumber); var transfer = new TransfersPay { openid = user.OpenId, amount = (int) order.Amount*100, partner_trade_no = order.OrderNumber, re_user_name = "stoneniqiu", spbill_create_ip = _webHelper.GetCurrentIpAddress() }; var data = transfer.GetTransfersApiParameters(); var result = WxPayApi.Transfers(data); return Content(result.ToPrintStr()); }
Get the result
In this way, the transfer/withdrawal function is realized.
Release
In a formal environment, we need to create our own order first, then request a transfer to WeChat, and process our order after success. CashTransfers method slightly adjusted.
[LoginValid] public ActionResult CashTransfers(string orderNumber) { var user = _workContext.CurrentUser; var order = _paymentService.GetOrderByOrderNumber(orderNumber); if (string.IsNullOrEmpty(user.OpenId)) { return Json(new PortalResult("请用微信登录!")); } if (order == null || order.OrderState != OrderState.Padding) { return Json(new PortalResult("订单有误!")); } var transfer = new TransfersPay { openid = user.OpenId, amount = (int) order.Amount*100, partner_trade_no = order.OrderNumber, re_user_name = "stoneniqiu", spbill_create_ip = _webHelper.GetCurrentIpAddress() }; var data = transfer.GetTransfersApiParameters(); var result = WxPayApi.Transfers(data); if (result.GetValue("result_code").ToString() == "SUCCESS") { return Json(new PortalResult(true, "提现成功")); } return Json(new PortalResult(false, result.GetValue("return_msg").ToString())); }
Another thing to note is that the operation timeout error always occurs after publishing. The suggestion is to change the timeout to 30 seconds. The default 6 seconds is prone to timeout. The same applies when placing orders together.
public static WxPayData Transfers(WxPayData inputData, int timeOut = 30)
If the money in the business account is gone, the following prompt will appear:
I believe you have mastered the method after reading the case in this article, please come for more exciting information Pay attention to other related articles on php Chinese website!
Recommended reading:
Usage of webpack automatic refresh and parsingUse of H5 cache ManifestThe above is the detailed content of Activation of enterprise transfer to user interface. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

As one of the world's largest short video platforms, Douyin has attracted the attention of many brands and businesses. Advertising on Douyin is an important means of publicity and promotion for many companies. So, how to activate the Douyin advertising sharing model? This issue will be discussed below. 1. How to activate Douyin advertising sharing? To activate Douyin advertising sharing, you need to perform the following steps: Register and log in: Register an account on the Douyin advertising platform, and use this account to log in to the advertiser backend. Create an advertising plan: In the advertiser's backend, choose to create an advertising plan and fill in the relevant advertising information, including advertising type, delivery period, budget, etc. Target the audience: Based on the characteristics of the product or service, select the appropriate target audience group and set targeting conditions such as region, age, gender, etc. system

When we assemble the computer, although the installation process is simple, we often encounter problems in the wiring. Often, users mistakenly plug the power supply line of the CPU radiator into the SYS_FAN. Although the fan can rotate, it may not work when the computer is turned on. There will be an F1 error "CPUFanError", which also causes the CPU cooler to be unable to adjust the speed intelligently. Let's share the common knowledge about the CPU_FAN, SYS_FAN, CHA_FAN, and CPU_OPT interfaces on the computer motherboard. Popular science on the CPU_FAN, SYS_FAN, CHA_FAN, and CPU_OPT interfaces on the computer motherboard 1. CPU_FANCPU_FAN is a dedicated interface for the CPU radiator and works at 12V

WeChat is an instant messaging application launched by Tencent. It supports cross-platform and cross-operator message sending and receiving. It has rich functions, including voice, video chat, and sharing in Moments. It is deeply loved by the majority of users. WeChat Pay is a payment function in WeChat Wallet, providing users with a more convenient payment experience. Let’s learn how to activate WeChat Pay. How to activate WeChat Pay? WeChat Pay Activation Settings 1. Open WeChat on your mobile phone, click [Me] in the lower right corner to enter the personal homepage, 2. Click the [Service] option. 3. Then click the [Wallet] icon. 4. Under the [Wallet] section, click [Split Payment] to enter the introduction page. 5. At the bottom of the payment introduction page, click the [View my payment limit] button. 6. Read the distribution carefully

As a modern and efficient programming language, Go language has rich programming paradigms and design patterns that can help developers write high-quality, maintainable code. This article will introduce common programming paradigms and design patterns in the Go language and provide specific code examples. 1. Object-oriented programming In the Go language, you can use structures and methods to implement object-oriented programming. By defining a structure and binding methods to the structure, the object-oriented features of data encapsulation and behavior binding can be achieved. packagemaini

Analysis of user password storage mechanism in Linux system In Linux system, the storage of user password is one of the very important security mechanisms. This article will analyze the storage mechanism of user passwords in Linux systems, including the encrypted storage of passwords, the password verification process, and how to securely manage user passwords. At the same time, specific code examples will be used to demonstrate the actual operation process of password storage. 1. Encrypted storage of passwords In Linux systems, user passwords are not stored in the system in plain text, but are encrypted and stored. L

Oracle database is a commonly used relational database management system, and many users will encounter problems with the use of table spaces. In Oracle database, a user can have multiple table spaces, which can better manage data storage and organization. This article will explore how a user can have multiple table spaces in an Oracle database and provide specific code examples. In Oracle database, table space is a logical structure used to store objects such as tables, indexes, and views. Every database has at least one tablespace,
