php 支付宝支付

公良育
2023-12-01
 
 
<?php
class AlipayAction extends CommonAction{
	public function __construct() {
		parent::__construct();
		
	}
	public function _initialize(){
		
		vendor('PCAlipay.lib.alipay_submit');
		vendor('PCAlipay.lib.alipay_notify');
	}
	public function config(){
        $alipay_config = array(
	    'seller_email'=>'***@163.com',
            'partner' => '***',       
            'seller_id' => '***',   
            'key' => '***',   
            'notify_url' => 'http://'.$_SERVER['HTTP_HOST'].'/Alipay/notifyurl',   
            'return_url' => 'http://'.$_SERVER['HTTP_HOST'].'/Alipay/returnurl',   
            'sign_type' => strtoupper('MD5'),
            'input_charset' => strtolower('utf-8'),
            'cacert' =>  getcwd().'\\cacert.pem',
            'transport' => 'http',
            'payment_type' => '1',
            'service' => 'create_direct_pay_by_user',
            'anti_phishing_key' => '',
            'exter_invoke_ip' => '',
        );
        return $alipay_config;
    }
    function getsubmit(){
        $alipay_config = $this->config();
        $format = "xml";
        $v = "2.0";
		

/**************************请求参数**************************/
        //商户订单号,商户网站订单系统中唯一订单号,必填
        $out_trade_no = $_GET['number'];

        //订单名称,必填
        $subject = $title;

        //付款金额,必填
        $total_fee = $count;
    // $total_fee = '0.01';

        //商品描述,可空
        $body = '';





/************************************************************/
//构造要请求的参数数组,无需改动
$parameter = array(
		"service"       => $alipay_config['service'],
		"partner"       => $alipay_config['partner'],
		"seller_id"  => $alipay_config['seller_id'],
		"payment_type"	=> $alipay_config['payment_type'],
		"notify_url"	=> $alipay_config['notify_url'],
		"return_url"	=> $alipay_config['return_url'],
		
		"anti_phishing_key"=>$alipay_config['anti_phishing_key'],
		"exter_invoke_ip"=>$alipay_config['exter_invoke_ip'],
		"out_trade_no"	=> $out_trade_no,
		"subject"	=> $subject,
		"total_fee"	=> $total_fee,
		"body"	=> $body,
		"_input_charset"	=> trim(strtolower($alipay_config['input_charset']))
		//其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.kiX33I&treeId=62&articleId=103740&docType=1
        //如"参数名"=>"参数值"
		
);
//dump($parameter);exit;
//建立请求
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestForm($parameter,"get", "确认");

        
 $html_text = $alipaySubmit->buildRequestForm($parameter, 'get', '确认');
        echo '<div style="display:none">'.$html_text.'</div>支付跳转中...';
		
	
		
    }

	public function notifyurl(){
		$config = $this->config();
		$arr=$_POST;
		$alipayNotify = new AlipayNotify($config);
		$verify_result = $alipayNotify->verifyReturn();


		if($verify_result) {//验证成功
	/
    		//请在这里加上商户的业务逻辑程序代码
    		
    		//——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
    	    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表

    		//商户订单号
    		$out_trade_no = $_POST['out_trade_no'];

    		//支付宝交易号
    		$trade_no = $_POST['trade_no'];

    		//交易状态
    		$result = $_POST['result'];
			
	
	
		echo 'success';
			
		//echo 'error';
			
			
	
	
	
	}
	
}
	public function returnurl(){
		$config = $this->config();
		$arr=$_GET;
		$alipayNotify = new AlipayNotify($config);
		$verify_result = $alipayNotify->verifyReturn();


		if($verify_result) {//验证成功
	/
    		//请在这里加上商户的业务逻辑程序代码
    		
    		//——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
    	    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表

    		//商户订单号
    		$out_trade_no = $_GET['out_trade_no'];


    		//支付宝交易号
    		$trade_no = $_GET['trade_no'];


    		//交易状态
    		$result = $_GET['result'];
	
	
		$this->success('支付成功',$url);
			
			
	
	
	
	}
	
}


}
?>


 类似资料: