本文实例为大家分享了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"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;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com