主頁 > 知識(shí)庫 > Thinkphp 5.0實(shí)現(xiàn)微信企業(yè)付款到零錢

Thinkphp 5.0實(shí)現(xiàn)微信企業(yè)付款到零錢

熱門標(biāo)簽:服務(wù)器配置 科大訊飛語音識(shí)別系統(tǒng) 阿里云 團(tuán)購網(wǎng)站 Mysql連接數(shù)設(shè)置 電子圍欄 銀行業(yè)務(wù) Linux服務(wù)器

本文實(shí)例為大家分享了Thinkphp 5.0 微信企業(yè)付款到零錢的具體代碼,供大家參考,具體內(nèi)容如下

【微信支付】企業(yè)付款到零錢:官方文檔

注意:1,證書路徑一定要寫絕對(duì)路徑,且使用函數(shù)getcwd()。

function transfer($data){
  //支付信息
  $wxchat['appid'] = WxPayConfig::$appid;
  $wxchat['mchid'] = WxPayConfig::$mchid;
  $webdata = array(
  'mch_appid' => $wxchat['appid'],//商戶賬號(hào)appid
    'mchid'  => $wxchat['mchid'],//商戶號(hào)
  'nonce_str' => md5(time()),//隨機(jī)字符串
    'partner_trade_no'=> date('YmdHis'), //商戶訂單號(hào),需要唯一
  'openid' => $data['openid'],//轉(zhuǎn)賬用戶的openid
  'check_name'=> 'NO_CHECK', //OPTION_CHECK不強(qiáng)制校驗(yàn)真實(shí)姓名, FORCE_CHECK:強(qiáng)制 NO_CHECK:
  'amount' => $data['money']*100, //付款金額單位為分
  'desc' => '微信企業(yè)付款到零錢',//企業(yè)付款描述信息
  'spbill_create_ip' => request()->ip(),//獲取IP
  );
  foreach ($webdata as $k => $v) {
  $tarr[] =$k.'='.$v;
  }
  sort($tarr);
  $sign = implode($tarr, '');
  $sign .= 'key='.WxPayConfig::$key;
  $webdata['sign']=strtoupper(md5($sign));
  $wget = $this->ArrToXml($webdata);//數(shù)組轉(zhuǎn)XML
  $pay_url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';//api地址
  $res = $this->postData($pay_url,$wget);//發(fā)送數(shù)據(jù)
  if(!$res){
  return array('status'=>1, 'msg'=>"Can't connect the server" );
  }
  $content = simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA);
  if(strval($content->return_code) == 'FAIL'){
  return array('status'=>1, 'msg'=>strval($content->return_msg));
  }
  if(strval($content->result_code) == 'FAIL'){
  return array('status'=>1, 'msg'=>strval($content->err_code),':'.strval($content->err_code_des));
  }
  $rdata = array(
  'mch_appid'  => strval($content->mch_appid),
  'mchid'   => strval($content->mchid),
  'device_info'  => strval($content->device_info),
  'nonce_str'  => strval($content->nonce_str),
  'result_code'  => strval($content->result_code),
  'partner_trade_no' => strval($content->partner_trade_no),
  'payment_no'  => strval($content->payment_no),
  'payment_time'  => strval($content->payment_time),
  );
  return $rdata;
}
//數(shù)組轉(zhuǎn)XML
 function ArrToXml($arr)
 {
  if(!is_array($arr) || count($arr) == 0) return '';
  $xml = "xml>";
  foreach ($arr as $key=>$val)
  {
   if (is_numeric($val)){
    $xml.="".$key.">".$val."/".$key.">";
   }else{
    $xml.="".$key.">![CDATA[".$val."]]>/".$key.">";
   }
  }
  $xml.="/xml>";
  return $xml;
 }


//發(fā)送數(shù)據(jù)
 function postData($url,$postfields){
  $ch = curl_init();
  $params[CURLOPT_URL] = $url; //請(qǐng)求url地址
  $params[CURLOPT_HEADER] = false; //是否返回響應(yīng)頭信息
  $params[CURLOPT_RETURNTRANSFER] = true; //是否將結(jié)果返回
  $params[CURLOPT_FOLLOWLOCATION] = true; //是否重定向
  $params[CURLOPT_POST] = true;
  $params[CURLOPT_POSTFIELDS] = $postfields;
  $params[CURLOPT_SSL_VERIFYPEER] = false;
  $params[CURLOPT_SSL_VERIFYHOST] = false;
  //以下是證書相關(guān)代碼
  $params[CURLOPT_SSLCERTTYPE] = 'PEM';
  $params[CURLOPT_SSLCERT] = getcwd().'/plugins/payment/weixin/cert/apiclient_cert.pem';//絕對(duì)路徑
  $params[CURLOPT_SSLKEYTYPE] = 'PEM';
  $params[CURLOPT_SSLKEY] = getcwd().'/plugins/payment/weixin/cert/apiclient_key.pem';//絕對(duì)路徑
  curl_setopt_array($ch, $params); //傳入curl參數(shù)
  $content = curl_exec($ch); //執(zhí)行
  curl_close($ch); //關(guān)閉連接
  return $content;
 }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • PHP實(shí)現(xiàn)微信商戶支付企業(yè)付款到零錢功能
  • php實(shí)現(xiàn)微信支付之企業(yè)付款
  • PHP編程實(shí)現(xiàn)微信企業(yè)向用戶付款的方法示例
  • php實(shí)現(xiàn)微信企業(yè)轉(zhuǎn)賬功能
  • 微信企業(yè)轉(zhuǎn)賬之入口類分裝php代碼
  • php實(shí)現(xiàn)微信公眾號(hào)企業(yè)轉(zhuǎn)賬功能
  • PHP微信企業(yè)號(hào)開發(fā)之回調(diào)模式開啟與用法示例
  • PHP實(shí)現(xiàn)微信公眾號(hào)企業(yè)號(hào)自定義菜單接口示例
  • PHP編程之微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口示例【回調(diào)操作】
  • php微信公眾號(hào)開發(fā)之微信企業(yè)付款給個(gè)人

標(biāo)簽:江蘇 大理 萍鄉(xiāng) 衢州 廣元 蚌埠 衡水 棗莊

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Thinkphp 5.0實(shí)現(xiàn)微信企業(yè)付款到零錢》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266