//支付寶條碼支付,直接調(diào)用ali_tiaoma_pay方法,把條碼和金額傳進(jìn)去就ok
function ali_tiaoma_pay($tiaoma,$price){
$data['scene'] = 'bar_code'; //支付場(chǎng)景
$data['out_trade_no'] = date("Ymd").rand(10000,99999); //訂單號(hào)
$data['total_amount'] = $price; //支付金額
$data['auth_code'] = $tiaoma; //支付授權(quán)碼
$data['subject'] = '訂單標(biāo)題'; //訂單標(biāo)題
$data['body'] = '訂單說(shuō)明'; //訂單說(shuō)明
$data = json_encode($data);
$params['app_id'] = $alipay_account;
$params['method'] = 'alipay.trade.pay';
$params['charset'] = 'utf-8';
$params['sign_type'] = 'RSA2';
$params['timestamp'] = date("Y-m-d H:i:s");
$params['version'] = '1.0';
$params['notify_url'] = "";
$params['biz_content'] = $data;
ksort($params); //對(duì)將要簽名的數(shù)組排序
$string = $this->toUrlParam($params); //將數(shù)組轉(zhuǎn)換成字符串
$params['sign'] = $this->alipay_sign($string); //將字符串簽名
$url = 'https://openapi.alipay.com/gateway.do?' . http_build_query($params);
$return = file_get_contents($url); //打開(kāi)支付請(qǐng)求連接 獲取二維碼地址
$return = json_decode($return, true); //將返回的字符串轉(zhuǎn)換為數(shù)組
return $return;
}
//app支付寶簽名
function alipay_sign($data, $signType = "RSA2")
$res = "-----BEGIN RSA PRIVATE KEY-----\n" .
wordwrap('你的商戶私鑰,必須和公匙匹配', 64, "\n", true) .
"\n-----END RSA PRIVATE KEY-----";
($res) or die('您使用的私鑰格式錯(cuò)誤,請(qǐng)檢查RSA私鑰配置');
if ("RSA2" == $signType) {
openssl_sign($data, $sign, $res, "SHA256");
} else {
openssl_sign($data, $sign, $res);
}
$sign = base64_encode($sign);
return $sign;
}
/*
* 格式化參數(shù)格式化成url參數(shù)
*/
function toUrlParam($param){
$buff = "";
foreach($param as $k => $v)
{
if($k != "sign" $v != "" !is_array($v)){
$buff .= $k."=".$v."";
}
}
$buff = trim($buff, "");
return $buff;
}