Thinkphp 5.0實(shí)現(xiàn)微信企業(yè)付款到零錢
本文實(shí)例為大家分享了Thinkphp 5.0 微信企業(yè)付款到零錢的具體代碼,供大家參考,具體內(nèi)容如下
【微信支付】企業(yè)付款到零錢:官方文檔
注意:1,證書(shū)路徑一定要寫絕對(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;
//以下是證書(shū)相關(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)開(kāi)發(fā)之回調(diào)模式開(kāi)啟與用法示例
- PHP實(shí)現(xiàn)微信公眾號(hào)企業(yè)號(hào)自定義菜單接口示例
- PHP編程之微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口示例【回調(diào)操作】
- php微信公眾號(hào)開(kāi)發(fā)之微信企業(yè)付款給個(gè)人
相關(guān)文章
phpcms模塊開(kāi)發(fā)之swfupload的使用介紹
本篇文章介紹了,phpcms模塊開(kāi)發(fā)之swfupload的使用分析,需要的朋友參考下2013-04-04
PHP使用fopen與file_get_contents讀取文件實(shí)例分享
這篇文章主要介紹了PHP使用fopen與file_get_contents讀取文件實(shí)例分享的相關(guān)資料,需要的朋友可以參考下2016-03-03
PHP讀取mssql json數(shù)據(jù)中文亂碼的解決辦法
PHP及網(wǎng)頁(yè)使用UTF-8編碼,數(shù)據(jù)庫(kù)是sql server2008,使用默認(rèn)編碼,當(dāng)讀取數(shù)據(jù)庫(kù)數(shù)據(jù)時(shí),使用php自帶的json_encode()返回到前端,結(jié)果中文不顯示。下面腳本之家小編給大家介紹PHP讀取mssql json數(shù)據(jù)中文亂碼的解決辦法,需要的朋友一起學(xué)習(xí)2016-04-04
Laravel中的chunk組塊結(jié)果集處理與注意問(wèn)題
這篇文章主要給大家介紹了關(guān)于Laravel中chunk組塊結(jié)果集處理與使用中要注意問(wèn)題的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08
CodeIgniter讀寫分離實(shí)現(xiàn)方法詳解
這篇文章主要介紹了CodeIgniter讀寫分離實(shí)現(xiàn)方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了CodeIgniter讀寫分離的相關(guān)配置與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-01-01
基于Linux調(diào)試工具strace與gdb的常用命令總結(jié)
本篇文章是對(duì)Linux調(diào)試工具strace與gdb的常用命令進(jìn)行了總結(jié)與分析,需要的朋友參考下2013-06-06

