设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php支付宝系列之电脑网站支付(2)

发布时间:2021-05-24 02:17 所属栏目:121 来源:网络整理
导读:protected function sign($data,$signType = "RSA") { $priKey=$this-rsaPrivateKey; $res = "-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap($priKey,64,"\n",true) . "\n-----END RSA PRIVATE KEY-----"; ($res)

protected function sign($data,$signType = "RSA") {
$priKey=$this->rsaPrivateKey;
$res = "-----BEGIN RSA PRIVATE KEY-----\n" .
wordwrap($priKey,64,"\n",true) .
"\n-----END RSA PRIVATE KEY-----";

($res) or die('您使用的私钥格式错误,请检查RSA私钥配置');
if ("RSA2" == $signType) {
  openssl_sign($data,$sign,$res,version_compare(PHP_VERSION,'5.4.0','<') ? SHA256 : OPENSSL_ALGO_SHA256); //OPENSSL_ALGO_SHA256是php5.4.8以上版本才支持
} else {
  openssl_sign($data,$res);
}
$sign = base64_encode($sign);
return $sign;

}

/**

  • 校验$value是否非空
  • if not set,return true;
  • if is null,return true;
    **/
    protected function checkEmpty($value) {
    if (!isset($value))
    return true;
    if ($value === null)
    return true;
    if (trim($value) === "")
    return true;
return false;

}

public function getSignContent($params) {
ksort($params);
$stringToBeSigned = "";
$i = 0;
foreach ($params as $k => $v) {
if (false === $this->checkEmpty($v) && "@" != substr($v,1)) {
// 转换成目标字符集
$v = $this->characet($v,$this->charset);
if ($i == 0) {
$stringToBeSigned .= "$k" . "=" . "$v";
} else {
$stringToBeSigned .= "&" . "$k" . "=" . "$v";
}
$i++;
}
}

unset ($k,$v);
return $stringToBeSigned;

}

/**

  • 转换字符集编码
  • @param $data
  • @param $targetCharset
  • @return string
    */
    function characet($data,$targetCharset) {
    if (!empty($data)) {
    $fileType = $this->charset;
    if (strcasecmp($fileType,$targetCharset) != 0) {
    $data = mb_convert_encoding($data,$targetCharset,$fileType);
    //$data = iconv($fileType,$targetCharset.'//IGNORE',$data);
    }
    }
    return $data;
    }
    }

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

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读