PHP programming method example for enterprises to pay users, php example
This article describes how to implement enterprise-to-user payment through PHP programming. We will share this with you for your reference. The details are as follows:
<? Phpheader ('content-type: text/html; charset = UTF-8 '); $ data ['mch _ appid '] = '##################'; // The Merchant's application appid $ data ['mchid'] = '################'; // merchant ID $ data ['nonce _ str'] = '000000'; // unicode (); // The method $ data ['partner _ trade_no '] = 'lb123456' under this is said to be a unique string ';//. time (); // This is the order number. $ Data ['openid'] = '000000'; // This is the openid of the authorized user .. This must be authorized by the user to use $ data ['check _ name'] = 'no _ check '; // set whether to check the real user name. $ data ['re _ user_name '] = '######'; // user's real name $ data ['amount'] = '1'; // withdrawal amount $ data ['desc'] = 'service '; // order description $ data ['spbill _ create_ip '] = $ _ SERVER ['server _ ADDR']; // This is the most annoying ,, you must obtain the Server ip address $ secrect_key = '############################### ##'; /// this is an API password. .. $ Data = array_filter ($ data); ksort ($ data); $ str = ''; foreach ($ data as $ k => $ v) {$ str. = $ k. '= '. $ v. '&';} $ str. = 'key = '. $ secrect_key; $ data ['sign'] = md5 ($ str); $ xml = arraytoxml ($ data); // echo $ xml; $ url = 'https: // encode ($ xml, $ url); $ return = xmltoarray ($ res); print_r ($ return); // echo getcwd (). '/cert/apiclient_cert.pem'; die; function unicode () {$ str = uniqid (mt_rand (), 1); $ str = sha1 ($ str ); return md5 ($ str);} function arraytoxml ($ data) {$ str = '<xml>'; foreach ($ data as $ k = >$ v) {$ str. = '<'. $ k. '> '. $ v. '</'. $ k. '>';} $ str. = '</xml>'; return $ str;} function xmltoarray ($ xml) {// disable the reference of an external xml Entity libxml_disable_entity_loader (true); $ xmlstring = simplexml_load_string ($ xml, 'simplexmlelement', LIBXML_NOCDATA); $ val = json_decode (json_encode ($ xmlstring), true); return $ val;} function curl ($ param = "", $ url) {$ postUrl = $ url; $ curlPost = $ param; $ ch = curl_init (); // initialize curl curl_setopt ($ ch, CURLOPT_URL, $ postUrl ); // capture the specified webpage curl_setopt ($ ch, CURLOPT_HEADER, 0); // set the header curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); // The result must be a string and be output to the screen. curl_setopt ($ ch, CURLOPT_POST, 1); // The post submission method curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ curlPost ); // Add the curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE) field in the HTTP Header (Header); // terminate the slave server to verify curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt ($ ch, CURLOPT_SSLCERT, getcwd (). '/cert/apiclient_cert.pem'); // The certificate location: curl_setopt ($ ch, CURLOPT_SSLKEY, getcwd (). '/cert/apiclient_key.pem'); // This is also the certificate location $ data = curl_exec ($ ch); // run curl curl_close ($ ch); return $ data ;}