您好,登錄后才能下訂單哦!
require_once "include/lib/Api.class.php";
require_once "include/lib/JsApiPay.class.php";
require_once "include/lib/PayNotifyCallBack.class.php";
require_once "include/lib/Config.class.php";
require_once "include/lib/JSSDK.class.php";
class WeiPay
{
//企業(yè)向個人付款
public static function payToUser($data)
{
//微信付款到個人的接口 前4個參數(shù),去微信平臺獲取
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
$params["mch_appid"] = 'wxed179f31e9bd43**'; //公眾賬號appid
$params["mchid"] = '153660**11'; //商戶號 微信支付平臺賬號
$params['key'] = '8ffbb9de88a5****edd1a14858b0'; //對應(yīng)的商戶號的key 秘鑰
$params["nonce_str"] = 'aedwnewe'.mt_rand(100,999); //隨機字符串
$params["partner_trade_no"] = mt_rand(10000000,99999999); //商戶訂單號
$params["amount"] = $data['pay_amount']; //金額
$params["desc"] = $data['order_title']; //企業(yè)付款描述
$params["openid"] = $data['openID']; //用戶openid
$params["check_name"] = 'NO_CHECK'; //不檢驗用戶姓名 固定值 可以
$params['spbill_create_ip'] = '101.37.163.73'; //獲取IP 服務(wù)器ip
//生成簽名(簽名算法后面詳細介紹)
$str = 'amount='.$params["amount"].'&check_name='.$params["check_name"].'&desc='.$params["desc"].
'&mch_appid='.$params["mch_appid"].'&mchid='.$params["mchid"].'&nonce_str='.$params["nonce_str"].
'&openid='.$params["openid"].'&partner_trade_no='.$params["partner_trade_no"].'&spbill_create_ip='.
$params['spbill_create_ip'].'&key='.$params['key'];
//md5加密 轉(zhuǎn)換成大寫
$sign = strtoupper(md5($str));
$params["sign"] = $sign;//簽名
$xml = self::arrayToXml($params);
return self::curl_post_ssl($url, $xml);
}
//遍歷數(shù)組方法
public static function arraytoxml($data){
$str='<xml>';
foreach($data as $k=>$v) {
$str.='<'.$k.'>'.$v.'</'.$k.'>';
}
$str.='</xml>';
return $str;
}
public static 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;
}
//上個方法中用到的curl_post_ssl()
public static function curl_post_ssl($url, $vars, $second = 30, $aHeader = array())
{
$isdir = "/www/wwwroot/qbb/tapi/storage/cert/";//證書位置
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_TIMEOUT, $second);//設(shè)置執(zhí)行最長秒數(shù)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求結(jié)果為字符串且輸出到屏幕上
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定網(wǎng)頁
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 終止從服務(wù)端進行驗證
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');//證書類型
curl_setopt($ch, CURLOPT_SSLCERT, $isdir . 'apiclient_cert.pem');//證書位置
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');//CURLOPT_SSLKEY中規(guī)定的私鑰的加密類型
curl_setopt($ch, CURLOPT_SSLKEY, $isdir . 'apiclient_key.pem');//證書位置
curl_setopt($ch, CURLOPT_CAINFO, 'PEM');
curl_setopt($ch, CURLOPT_CAINFO, $isdir . 'rootca.pem');
if (count($aHeader) >= 1) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);//設(shè)置頭部
}
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);//全部數(shù)據(jù)使用HTTP協(xié)議中的"POST"操作來發(fā)送
$data = curl_exec($ch);//執(zhí)行回話
if ($data) {
curl_close($ch);
$res = self::xmltoarray($data);
return $res;
} else {
$error = curl_errno($ch);
echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
}
}
注意:
1,金額必須是整數(shù),最低是30=3毛錢
2,用公眾號的APPID,對應(yīng)的商戶號 和key秘鑰
3,對應(yīng)的公眾號的openID
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。