PHP編程實現微信企業向使用者付款的方法

來源:互聯網
上載者:User
這篇文章主要介紹了PHP編程實現企業向使用者付款的方法,涉及php針對介面調用、配置及互動操作相關技巧,需要的朋友可以參考下

本文執行個體講述了PHP編程實現企業向使用者付款的方法。分享給大家供大家參考,具體如下:

<?phpheader('content-type:text/html;charset=utf-8');$data['mch_appid']='##################';//商戶的應用appid$data['mchid']='################';//商戶ID$data['nonce_str']='123456';//unicode();//這個據說是唯一的字串下面有方法$data['partner_trade_no']='LB123456';//.time();//這個是訂單號。$data['openid']='123';//這個是授權使用者的openid。。這個必須得是使用者授權才能用$data['check_name']='NO_CHECK';//這個是設定是否檢測使用者真實姓名的$data['re_user_name']='######';//使用者的真實名字$data['amount']='1';//提現金額$data['desc']='服務費';//訂單描述$data['spbill_create_ip']=$_SERVER['SERVER_ADDR'];//這個最煩了,,還得擷取伺服器的ip$secrect_key='#################################';///這個就是個API密碼。32位的。。隨便MD5一下就可以了$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://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';$res=curl($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) {   //禁止引用外部xml實體  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();                   //初始化curl  curl_setopt($ch, CURLOPT_URL,$postUrl);         //抓取指定網頁  curl_setopt($ch, CURLOPT_HEADER, 0);          //設定header  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      //要求結果為字串且輸出到螢幕上  curl_setopt($ch, CURLOPT_POST, 1);           //post提交方式  curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);      // 增加 HTTP Header(頭)裡的欄位  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    // 終止從服務端進行驗證  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  curl_setopt($ch,CURLOPT_SSLCERT,getcwd().'/cert/apiclient_cert.pem'); //這個是認證的位置  curl_setopt($ch,CURLOPT_SSLKEY,getcwd().'/cert/apiclient_key.pem'); //這個也是認證的位置  $data = curl_exec($ch);                 //運行curl  curl_close($ch);  return $data;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.