一个php文件实现支付宝身份认证

本文介绍如何使用PHP生成二维码并处理回调,实现支付宝的身份认证过程。
摘要由CSDN通过智能技术生成

一个php文件实现支付宝身份认证

1、生成二维码

<?php
header('Content-type:text/html; Charset=utf-8');
/*** 请填写以下配置信息 ***/
$appid = 'xxxxx';    //https://open.alipay.com 账户中心->密钥管理->开放平台密钥,填写开通了“支付宝身份验证”应用的APPID
$outTradeNo = strtoupper(md5(uniqid()));     //商户请求的唯一标识,不能重复
$certName = '张三';		//真实姓名。填写需要验证的真实姓名
$certNo = 'xxxxx';		//身份证号码。填写需要验证的证件号码
$returnUrl = 'http://www.xxx.com';		//需要回跳的目标地址,一般指定为商户业务页面
//商户私钥,填写对应签名算法类型的私钥,如何生成密钥参考:https://docs.open.alipay.com/291/105971和https://docs.open.alipay.com/200/105310
$rsaPrivateKey='xxxxx';
/*** 配置结束 ***/
$aliPay = new AlipayService();
$aliPay->setAppid($appid);
$aliPay->setOutTradeNo($outTradeNo);
$aliPay->setCertName($certName);
$aliPay->setCertNo($certNo);
$aliPay->setReturnUrl($returnUrl);
$aliPay->setRsaPrivateKey($rsaPrivateKey);
if(isAlipay()):
    $result = $aliPay->initialize();
    $response = $result['alipay_user_certify_open_initialize_response'];
    if($response && $response['code']=='10000'){
   
        $url = $aliPay->getCertifyUrl($response['certify_id']);
        header("Location:{
     $url}");
        exit();
    }else{
   
        echo $response['msg'].' : '.$response['sub_msg'];
    }
else:
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="UTF-8">
    <title>支付宝实名认证</title>
    <link href="https://cdn.dedemao.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.dedemao.com/jquery/2.1.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
    <h1 align="center">支付宝身份验证(实名认证)</h1>
    <h3>请使用支付宝APP扫码进行实名认证:</h3>
    <img src="https://sapi.k780.com/?app=qr.get&level=H&size=6&data=<?php echo getCurrentUrl()?>" />
    <br>
</div>
</body>
</html>
<?php
endif;
class AlipayService
{
   
    protected $appId;
    protected $charset;
    //私钥值
    protected $rsaPrivateKey;
    protected $outTradeNo;
    protected $returnUrl;
    protected $certName;
    protected $certNo;
    public function __construct()
    {
   
        $this->charset = 'utf-8';
    }
    public function setAppid($appid)
    {
   
        $this->appId = $appid;
    }
    public function setOutTradeNo($outTradeNo)
    {
   
        $this->outTradeNo = $outTradeNo;
    }
	public function setCertName($certName)
    {
   
        $this->certName = $certName;
    }
	public function setCertNo($certNo)</
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海弟君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值