Payment, enterprise number payment for individual, php implementation lead: distributors, micro-business withdrawal how to mention? Pay directly.
The implementation is as follows:
/* Payment */'pay _ WEIXIN '=> array ('appid' => 'XXX', 'appsecret' => 'xxxxx ', 'mkid' => '20140901', // merchant ID 'key' => 'zhudianbaodiandozhudianbao0527 ', // The Merchant's payment key 'apiclient _ cert' => 'conf/cert/apiclient_cert.pem ', // The merchant certificate apiclient_cert.pem 'apiclient _ key' => 'conf/cert/certificate ', // merchant certificate apiclient_key.pem)
ArrayToXml
/*** Convert array to xml */function arrayToXml ($ arr) {$ xml ="
"; Foreach ($ arr as $ key => $ val) {if (is_numeric ($ val) {$ xml. = "<". $ key. "> ". $ val."
";} Else $ xml. =" <". $ key.">".$val."
";}$ Xml. ="
"; Return $ xml ;}
Use the certificate to submit xml to the corresponding interface url in post mode
/*** Function: Use the certificate to submit xml to the corresponding interface url in post mode */function postXmlSSLCurl ($ xml, $ url, $ second, $ cert, $ key) {$ ch = curl_init (); // timeout curl_setopt ($ ch, CURLOPT_TIMEOUT, $ second? $ Second: $ this-> timeout); // Set the proxy here. if yes, // curl_setopt ($ ch, CURLOPT_PROXY, '8. 8.8.8 '); // curl_setopt ($ ch, CURLOPT_PROXYPORT, 8080); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE); // Set the header curl_setopt ($ ch, CURLOPT_HEADER, FALSE); // The result must be a string and be output to curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE); // Set the certificate // use the certificate: cert and key belong to two. pem file // the default format is PEM. you can comment curl_setopt ($ ch, CURLOPT_SSLCERTTYPE, 'pem'); curl_setopt ($ ch, CURLOPT_SSLCERT, $ cert ); // the default format is PEM. you can comment out curl_setopt ($ ch, CURLOPT_SSLKEYTYPE, 'pem'); curl_setopt ($ ch, CURLOPT_SSLKEY, $ key ); // post submission method: curl_setopt ($ ch, CURLOPT_POST, true); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ xml); $ data = curl_exec ($ ch ); // return result if ($ data) {curl_close ($ ch); return $ this-> xmlToArray ($ data);} else {$ error = curl_errno ($ ch ); echo "curl error, error code: $ error "."
"; Curl_close ($ ch); return false ;}}
- Enterprise Payment to individual
// The enterprise pays an individual public function payToUser ($ params, $ key, $ apicent_cert, $ apiclient_key) {$ url = 'https: // required // Check Required parameter if ($ params ["partner_trade_no"] = null) {// exit ("The required parameter partner_trade_no is missing in the refund request interface! "."
");} Elseif ($ params [" openid "] = null) {exit (" The required parameter openid is missing in the refund application interface! "."
");} Elseif ($ params [" check_name "] = null) {// NO_CHECK: do not verify the real name FORCE_CHECK: strong verification of real names (non-real-name authentication of users will fail to verify, unable to transfer) OPTION_CHECK: for users with real-name authentication to verify the real name (not verified by users without real-name authentication, transfer successful) exit ("The required parameter check_name is missing in the refund application interface! "."
");} Elseif ($ params [" check_name "] = 'force _ check' or $ params [" check_name "] = 'option _ check ') & ($ params ["re_user_name"] = null) {// real name of the recipient. Exit ("The required parameter re_user_name is missing in the refund request interface! "."
");} Elseif ($ params [" amount "] = null) {exit (" The required parameter amount is missing in the refund request interface! "."
");} Elseif ($ params [" desc "] = null) {exit (" The required parameter desc is missing in the refund application interface! "."
") ;}$ Params [" mch_appid "] = $ this-> appid; // public account ID $ params [" mchid "] = $ this-> mchid; // merchant ID $ params ["nonce_str"] = $ this-> createNoncestr (); // random string $ params ['spbill _ create_ip '] = $ _ SERVER ['remote _ ADDR'] = ': 1 '? '2017. 127.1.1 ': $ _ SERVER ['remote _ ADDR']; // Get IP $ params ["sign"] = $ this-> getSign ($ params, $ key ); // signature $ xml = $ this-> arrayToXml ($ params); return $ this-> postXmlSSLCurl ($ xml, $ url, false, $ apicent_cert, $ apiclient_key );}
Private function _ performanisepay ($ number, $ member_id, $ amount, $ desc) {// get openid $ wxuser_id = M ('member ') -> where (array ('id' => $ member_id)-> getField ('wxuser _ id'); $ openid = M ('wxuser ') -> where (array ('id' => $ wxuser_id)-> getField ('openid'); $ pay = C ('pay _ WEIXIN '); import ('@. action. wxDevelop '); $ enterprise = new WxEnterprise ($ pay ['appid'], $ pay ['appsecret'], $ pay ['mchid']); $ params = array ('partner _ trade_no '=> $ number, 'openid' => $ openid, 'Check _ name' => 'No _ check ', 'amount '=> $ amount, // Total 'desc' => $ desc,); $ result = $ enterprise-> payToUser ($ params, $ pay ['key'], $ pay ['apiclient _ cert'], $ pay ['apiclient _ key']); return $ result ;}
- Process distributor withdrawal
Private function _ handle ($ truename, $ price) {// process reseller withdrawal $ withdrawid = date ("ymdHis "). strval (rand (1000,999 9); $ data = array ('withdrawid' => $ withdrawid, 'Store _ id' => $ this-> store_id, 'member _ id' => $ this-> member_id, 'truename' => $ truename, 'price' => $ price, 'addtime' => time ()); // audit-free if ($ price> = C ('withdraw _ uncheck_value ') {$ data ['need _ check'] = 0; $ data ['status'] = 1; if ($ this-> withdr AwModel-> add ($ data) {$ result = $ this-> _ your isepay ($ withdrawid, $ this-> member_id, $ price * 100, 'distributor ('. $ truename. ') withdrawal'); // if a payment information error occurs, the request must be reviewed. if ($ result ['return _ Code']! = 'Success ') {$ this-> withdrawModel-> where (array ('withdrawid' => $ withdrawid )) -> save (array ('need _ check' => 1, 'status' => 0); $ this-> assign ('success', 2 );} else {// Set the transaction number $ this-> withdrawModel-> where (array ('withdrawid' => $ withdrawid )) -> save (array ('payment _ no' => $ result ['payment _ no']); // add Commission flow, $ data = array ('store _ id' => $ this-> store_id, 'User _ type' => 2, 'user _ id' => $ this-> shop_id, 'Trade _ Type '=> 2, 'Trade _ no' => $ withdrawid, 'price' =>-$ price, 'status' => 1, 'message' => $ truename. 'withdrawal ', 'addtime' => time (); M ('Twitter _ log')-> add ($ data ); // reduce Commission M ('member')-> where (array ('id' => $ this-> member_id)-> setInc ('Money ', -$ price); $ this-> assign ('success ', 1); // send the Commission change message import ('@. action. tmplmsg '); $ tmplmsg = new Tmplmsg (); $ tmplmsg-> send (Tmplmsg: PRICE_CHANGE, $ this-> member_id, array ('Token' => $ this-> token, 'Intro' => 'distribution Commission withdrawal transfer ', 'price' => $ price, 'business' => business) ;}} else {$ this-> error ('withdrawal information error! ') ;}} // Else to be reviewed {$ this-> withdrawModel-> add ($ data); $ this-> assign ('success', 2 );}}
It provides the ability for enterprises to make payments to users, and supports enterprises to make payments through API interfaces or through the web page of the payment merchant platform.
Tip: ◆ Pay for the same real-name user with a single daily quota of 2 W/2 W ◆ Pay for the same non-real-name user, A single payment limit of 2000/2000 per day ◆ a merchant's total payment limit of per day ◆ only supports the APPID bound to the merchant's account; ◆ target users for payment, users with paid real-name authentication can verify their real names. users without real-name authentication cannot verify their real names. enterprises can select a verification type based on their own business security level; ◆ the payment amount must be less than or equal to the amount available for the merchant's current balance; ◆ payment records, enterprises can view the corresponding data through enterprise payment query.
The payment will go to the change for the target user (-I-wallet-change ). You will be notified of the change receipt and payment details. the corresponding records will be displayed.
Tip: For Historical client versions without change accounts, funds will enter the user's red envelope account, and no notification is sent to the user for payment. enterprises can choose to reach the user by themselves.
Interface: https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers
Whether a certificate request requires a two-way certificate.
Data example:
Wxe062425f740c30d8
10000098
3PG2J4ILTKCH16CQ2502SI8ZNMTM67VS
100000982014120919616
OhO4Gt7wVPxIT1A9GjFaMYMiZY1s
OPTION_CHECK
Zhang San
100
Happy holidays!
10.2.3.10
C97bdbacf37622775108f38b629f45e3
Successful example:
SUCCESS
wxec38b8ff840bd989
10013274
lxuDzMnRjpcXzxLx0q
SUCCESS
10013574201505191526582441
1000018301201505190181489473
2015-05-19 15:26:59
Error example:
FAIL
系统繁忙,请稍后再试.
FAIL
SYSTEMERROR
系统繁忙,请稍后再试.
Reference: https://pay.weixin.qq.com/wiki/doc/api/mch_pay.php? Chapter = 14_2