function transfer($data){
//支付信息
$wxchat['appid'] = WxPayConfig::$appid;
$wxchat['mchid'] = WxPayConfig::$mchid;
$webdata = array(
'mch_appid' => $wxchat['appid'],//商戶賬號appid
'mchid' => $wxchat['mchid'],//商戶號
'nonce_str' => md5(time()),//隨機字符串
'partner_trade_no'=> date('YmdHis'), //商戶訂單號,需要唯一
'openid' => $data['openid'],//轉賬用戶的openid
'check_name'=> 'NO_CHECK', //OPTION_CHECK不強制校驗真實姓名, FORCE_CHECK:強制 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ù)組轉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;
}
//發(fā)送數(shù)據(jù)
function postData($url,$postfields){
$ch = curl_init();
$params[CURLOPT_URL] = $url; //請求url地址
$params[CURLOPT_HEADER] = false; //是否返回響應頭信息
$params[CURLOPT_RETURNTRANSFER] = true; //是否將結果返回
$params[CURLOPT_FOLLOWLOCATION] = true; //是否重定向
$params[CURLOPT_POST] = true;
$params[CURLOPT_POSTFIELDS] = $postfields;
$params[CURLOPT_SSL_VERIFYPEER] = false;
$params[CURLOPT_SSL_VERIFYHOST] = false;
//以下是證書相關代碼
$params[CURLOPT_SSLCERTTYPE] = 'PEM';
$params[CURLOPT_SSLCERT] = getcwd().'/plugins/payment/weixin/cert/apiclient_cert.pem';//絕對路徑
$params[CURLOPT_SSLKEYTYPE] = 'PEM';
$params[CURLOPT_SSLKEY] = getcwd().'/plugins/payment/weixin/cert/apiclient_key.pem';//絕對路徑
curl_setopt_array($ch, $params); //傳入curl參數(shù)
$content = curl_exec($ch); //執(zhí)行
curl_close($ch); //關閉連接
return $content;
}