本文实例为大家分享了PHP支付宝当面付2.0代码,供大家参考,具体内容如下
//支付宝条码支付,直接调用ali_tiaoma_pay方法,把条码和金额传进去就ok function ali_tiaoma_pay($tiaoma,$price){ $data['scene'] = 'bar_code'; //支付场景 $data['out_trade_no'] = date("Ymd").rand(10000,99999); //订单号 $data['total_amount'] = $price; //支付金额 $data['auth_code'] = $tiaoma; //支付授权码 $data['subject'] = '订单标题'; //订单标题 $data['body'] = '订单说明'; //订单说明 $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); //对将要签名的数组排序 $string = $this->toUrlParam($params); //将数组转换成字符串 $params['sign'] = $this->alipay_sign($string); //将字符串签名 $url = 'https://openapi.alipay.com/gateway.do?' . http_build_query($params); $return = file_get_contents($url); //打开支付请求连接 获取二维码地址 $return = json_decode($return, true); //将返回的字符串转换为数组 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('您使用的私钥格式错误,请检查RSA私钥配置'); if ("RSA2" == $signType) { openssl_sign($data, $sign, $res, "SHA256"); } else { openssl_sign($data, $sign, $res); } $sign = base64_encode($sign); return $sign; } /* * 格式化参数格式化成url参数 */ function toUrlParam($param){ $buff = ""; foreach($param as $k => $v) { if($k != "sign" && $v != "" && !is_array($v)){ $buff .= $k."=".$v."&"; } } $buff = trim($buff, "&"); return $buff; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。