


WeChat public account red envelope distribution and corporate payment implementation methods
Mar 20, 2018 pm 02:17 PMWeChat cash red envelope is one of the marketing tools provided by the WeChat payment merchant platform. It has been deeply loved by merchants and users since its launch. Merchants can issue cash red envelopes to WeChat Pay users through this platform. After the user receives the red envelope, the funds arrive in the user's WeChat payment change account, which brings enthusiastic response to the merchant's marketing activities in daily operations.
1. You do not need to pay the authorization directory to send red envelopes, but you need to call the IP address of the red envelope API in the merchant's backend, which is the IP of your server that initiates the red envelope request. The operation path is: [Log in to the merchant platform——> Product Center——>Cash Red Envelope——>Product Settings] (Note: The “Product Settings” operation button will only appear after you activate the cash red envelope function).
2. Api certificate is required to send red envelopes.
3. Before issuing cash red envelopes, please make sure you have sufficient funds. The money others pay you through WeChat Pay for buying things on your platform is not the same as the money you need to spend to send red envelopes. The money here needs to be recharged separately. The operation path is: [Log in to the merchant platform——>Account Center——> ;Fund Management——>Recharge].
4. You can borrow rights when sending red envelopes. For example, public account A is a certification service account that has opened WeChat payment. Your event is held in public account B (subscription account or service account is acceptable). Public account B can use A. WeChat Pay sends red envelopes, but sending red envelopes requires knowing the user's openid. When obtaining this openid, you also need to borrow the public account A to obtain it. That is, the openid used to send red envelopes through A must be the openid corresponding to A of the user.
Pre-operation preparation, that is, some configurations of the WeChat payment merchant platform, please refer to the document: https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter= 13_3&index=2
In fact, sending red envelopes on WeChat public accounts is similar to corporate payments on WeChat public accounts, so I will sort out corporate payments by the way. Without further ado, I will directly upload the code:
/** * 公眾號發(fā)紅包 * @param string $openid 用戶openID * @param string $money 金額 * @param string $trade_no 訂單編號 * @param string $act_name 活動名稱 * @return multitype 支付結(jié)果 */ public function sendredpack($openid,$money,$trade_no,$act_name){ $config = $this->config; $data = array( 'nonce_str' => self::getNonceStr(), 'mch_billno' => $trade_no, 'mch_id' => $config['mch_id'], 'wxappid' => $config['wxappid'], 'send_name' => '江南極客', 're_openid' => $openid, 'total_amount' => $money * 100, //付款金額單位為分 'total_num' => 1, 'wishing' => '祝您天天開心!', 'client_ip' => self::getip(), 'act_name' => $act_name, 'remark' => 'From 江南極客' ); $data['sign'] = self::makeSign($data); //構(gòu)造XML數(shù)據(jù) $xmldata = self::array2xml($data); $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack'; //發(fā)送post請求 $res = self::curl_post_ssl($url, $xmldata); if(!$res){ return array('status'=>0, 'msg'=>"Can't connect the server" ); } // 這句file_put_contents是用來查看服務器返回的結(jié)果 測試完可以刪除了 //file_put_contents('./log.txt',$res,FILE_APPEND); $content = self::xml2array($res); if(strval($content['return_code']) == 'FAIL'){ return array('status'=>0, 'msg'=>strval($content['return_msg'])); } if(strval($content['result_code']) == 'FAIL'){ return array('status'=>0, 'msg'=>strval($content['err_code']).':'.strval($content['err_code_des'])); } return $content; } /** * 公眾號企業(yè)支付 * @param string $openid 用戶openID * @param string $money 金額 * @param string $trade_no 訂單編號 * @param string $desc 付款操作說明信息(比如:提現(xiàn)) * @return string 支付結(jié)果 */ public function mchpay($openid,$money,$trade_no,$desc){ $config = $this->config; $data = array( 'mch_appid' => $config['wxappid'], 'mchid' => $config['mch_id'], 'nonce_str' => self::getNonceStr(), 'partner_trade_no' => $trade_no, 'openid' => $openid, 'check_name'=> 'NO_CHECK', //OPTION_CHECK不強制校驗真實姓名, FORCE_CHECK:強制 NO_CHECK: 'amount' => $money * 100, //付款金額單位為分 'desc' => $desc, 'spbill_create_ip' => self::getip() ); //生成簽名 $data['sign'] = self::makeSign($data); //return $config; //構(gòu)造XML數(shù)據(jù) $xmldata = self::array2xml($data); $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; //發(fā)送post請求 $res = self::curl_post_ssl($url, $xmldata); if(!$res){ return array('status'=>0, 'msg'=>"Can't connect the server" ); } // 這句file_put_contents是用來查看服務器返回的結(jié)果 測試完可以刪除了 //file_put_contents('./log1.txt',$res,FILE_APPEND); //付款結(jié)果分析 $content = self::xml2array($res); if(strval($content['return_code']) == 'FAIL'){ return array('status'=>0, 'msg'=>strval($content['return_msg'])); } if(strval($content['result_code']) == 'FAIL'){ return array('status'=>0, 'msg'=>strval($content['err_code']).':'.strval($content['err_code_des'])); } return $content; }
This is an encapsulated class, and calling the method is super simple:
include 'wxmerpay.class.php'; //引入類文件 $config = array( 'wxappid' => 'wx123456789', 'mch_id' => '1123456781', 'pay_apikey' => '1234567898765432123456789', 'api_cert' => $cert_path . '/apiclient_cert.pem', 'api_key' => $cert_path . '/apiclient_key.pem', 'rootca' => $cert_path . '/rootca.pem' ); $redpack = new WxRedpack($config); //初始化 $redpack->sendredpack($openid,$money,$trade_no,$act_name); //發(fā)紅包
Is it that simple? right! It’s that simple, but it uses a lot of self-encapsulated functions and methods. Source code download: http://download.csdn.net/download/sinat_35861727/9956485
If you really find it useful, please give it a like and leave a like Good review, thank you! If you have any questions, you can tell me in the comment area!
Related recommendations:
WeChat payment refund function development
PHP development examples of WeChat payment and Alipay payment
Research and Sharing on WeChat Payment Interface
The above is the detailed content of WeChat public account red envelope distribution and corporate payment implementation methods. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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)

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

Implementing exact division operations in Golang is a common need, especially in scenarios involving financial calculations or other scenarios that require high-precision calculations. Golang's built-in division operator "/" is calculated for floating point numbers, and sometimes there is a problem of precision loss. In order to solve this problem, we can use third-party libraries or custom functions to implement exact division operations. A common approach is to use the Rat type from the math/big package, which provides a representation of fractions and can be used to implement exact division operations.

How to pay with Google Chrome? The Internet is developing rapidly, and we can already use Google Chrome to search and shop online. But some friends also want to know how to set up payment methods on Google Chrome so that we can pay for online shopping faster. The following is a tutorial on setting up payment methods on Google Chrome. Friends, you can start your online shopping journey by choosing a payment method that suits you. Tutorial on setting payment method on Google Chrome 1. Double-click to open the software and click on the three dots icon in the upper right corner. (As shown in the picture) 2. Then click "Settings" in the option list below. (As shown in the picture) 3. In the window interface that opens, click the "You and Google" option in the left column. (As shown in the picture

I'm really sorry that I can't provide real-time programming guidance, but I can provide you with a code example to give you a better understanding of how to use PHP to implement SaaS. The following is an article within 1,500 words, titled "Using PHP to implement SaaS: A comprehensive analysis." In today's information age, SaaS (Software as a Service) has become the mainstream way for enterprises and individuals to use software. It provides a more flexible and convenient way to access software. With SaaS, users don’t need to be on-premises
