php支付宝免密支付,代扣

请先在支付宝商家中心申请开通商家代扣接口

<?php 
namespace app\api\controller;
use think\Controller;
class Alifreepay  extends Controller
{
 
    
        //获取会员信息
          public  function  index(){
         
          $mac_id=123;
         $appid =config('config')['app_id'];
         $url=config('questurl').'/api/Alifreepay/receive';
         $redirect_uri = urlencode($url);
         $url ='https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id='.$appid.'&scope=auth_base&state='.$mac_id.'&redirect_uri='.$redirect_uri;
       // dump($url);exit;
         $this->redirect($url);
     }
        
        
        
        
        
        
        
        
        
        
        
     
         //支付宝跳转
    public  function   receive(){
      
    header("Content-type:text/html;charset=utf-8");
     //引入的SDK
       vendor('alipayclub.AopSdk');
       vendor('alipayclub.aop.AopClient');
       vendor('alipayclub.aop.request.AlipaySystemOauthTokenRequest');
       vendor('alipayclub.aop.request.AlipayUserUserinfoShareRequest');

       $code = $_GET['auth_code'];
       $_SESSION['mac_id']=$_GET['state'];
      //APPID 
      $appid = config('config')['app_id'];
      //私钥  文件名(rsa_private_key.pem)
      $rsaPrivateKey = config('config')['merchant_private_key'];
      //公钥  文件名 (rsa_public_key.pem)
      $alipayrsaPublicKey =config('config')['alipay_public_key'];
      //初始化
      $aop = new \AopClient();
      $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
      $aop->appId = $appid;
      $aop->rsaPrivateKey = $rsaPrivateKey;
      $aop->alipayrsaPublicKey = $alipayrsaPublicKey;
      $aop->apiVersion = '1.0';
      $aop->signType = 'RSA2';
      $aop->postCharset='UTF-8';
      $aop->format='json';

      //获取access_token
      $request = new \AlipaySystemOauthTokenRequest ();
      $request->setGrantType("authorization_code");
      $request->setCode($code);//这里传入 code
      $result = $aop->execute($request);
      $user_id=$result->alipay_system_oauth_token_response->user_id;
      var_dump($user_id);exit;
    
    }
    
    
    
    
    //查看是否签约
    public  function  check_signagreement(){
        $user_id='2088802809584550';
        $external_sign_no='1609918511';
      // $url='*******/zhima/query/query?user_id='.$user_id.'&external_sign_no='.$external_sign_no;
        
       $param['service']='alipay.dut.customer.agreement.query';
 	   	  $param['partner']=config('config')['partner'];
          $param['product_code']='GENERAL_WITHHOLDING_P';
          $param['alipay_user_id']=$user_id;
          $param['scene']='INDUSTRY|ALIPAYGO';
          $param['appid']=config('config')['app_id'];
          $param['external_sign_no']=$external_sign_no;
          $key=config('config')['md5key'];
          $sign=SinParams($param,$key);
         // $url='https://mapi.alipay.com/gateway.do?partner=2088121753340152&product_code=GENERAL_WITHHOLDING_P&service='.$param['service'].'&sign='.$sign.'&sign_type=MD5';
          $url='https://mapi.alipay.com/gateway.do?sign='.$sign.'&scene='.$param['scene'].'&external_sign_no='.$param['external_sign_no'].'&appid='.$param['appid'].'&product_code='.$param['product_code'].'&sign_type=MD5&service='.$param['service'].'&partner='.$param['partner'].'&alipay_user_id='.$param['alipay_user_id'];       // var_dump($url);
         $res=http_get($url);
          //xml转数组
         $values = json_decode(json_encode(simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA)), true);  
         dump($values);
        //array(5) { ["is_success"] => string(1) "T" ["request"] => array(1) { ["param"] => array(9) { [0] => string(16) "2088831484036885" [1] => string(35) "alipay.dut.customer.agreement.query" [2] => string(16) "2021002117666484" [3] => string(32) "410130066d15b20bcc2cc1461246a125" [4] => string(16) "2088802809584550" [5] => string(21) "GENERAL_WITHHOLDING_P" [6] => string(10) "1609918511" [7] => string(3) "MD5" [8] => string(17) "INDUSTRY|ALIPAYGO" } } ["response"] => array(1) { ["userAgreementInfo"] => array(14) { ["agreement_detail"] => string(2) "{}" ["agreement_no"] => string(20) "20214906678966429555" ["external_sign_no"] => string(10) "1609918511" ["invalid_time"] => string(19) "2115-02-01 00:00:00" ["pricipal_type"] => string(4) "CARD" ["principal_id"] => string(16) "2088802809584550" ["product_code"] => string(21) "GENERAL_WITHHOLDING_P" ["scene"] => string(17) "INDUSTRY|ALIPAYGO" ["sign_modify_time"] => string(19) "2021-01-06 15:35:52" ["sign_time"] => string(19) "2021-01-06 15:35:52" ["status"] => string(6) "NORMAL" ["thirdpart_id"] => string(16) "2088831484036885" ["thirdpart_type"] => string(7) "PARTNER" ["valid_time"] => string(19) "2021-01-06 15:35:52" } } ["sign"] => string(32) "92d0b9320c3fef3339269b931c9a5ab9" ["sign_type"] => string(3) "MD5" 
        
        
        
        
    }
    
    //进行签约
    public  function  signagreement(){
        
        //$param['external_sign_no']='2225'; 我的签约号
          $param['access_info']='{"channel":"ALIPAYAPP"}';
          $param['external_sign_no']=time();
          //$param['external_user_id']='0002';
          $param['partner']=config('config')['partner'];
          $param['product_code']='GENERAL_WITHHOLDING_P';
          //$param['return_url']='*******/zhima/sn/return_url';
          $param['scene']='INDUSTRY|ALIPAYGO';
          $param['service']='alipay.dut.customer.agreement.page.sign';
          $param['notify_url']=config('questurl').'/api/Alifreepay/notify';
          $key=config('config')['md5key'];
          $sign=SinParams($param,$key);
          $url='https://mapi.alipay.com/gateway.do?access_info={"channel":"ALIPAYAPP"}&partner='.$param['partner'].'&product_code=GENERAL_WITHHOLDING_P&scene=INDUSTRY|ALIPAYGO&external_sign_no='.$param['external_sign_no'].'&notify_url='.$param['notify_url'].'&service='.$param['service'].'&sign='.$sign.'&sign_type=MD5';
          
          //dump($url);
        $this->redirect($url);
        
    }
    
      //异步回调
    public  function  notify(){
       //  sign_modify_time=2021-01-06+15%3A35%3A52&notify_time=2021-01-06+15%3A35%3A52&alipay_user_id=2088802809584550&sign=2babd0ad96cad276ca6629d5334089b9&product_code=GENERAL_WITHHOLDING_P&sign_time=2021-01-06+15%3A35%3A52&notify_id=2021010600222153552048741410623441&scene=INDUSTRY%7CALIPAYGO&notify_type=dut_user_sign&partner_id=2088831484036885&agreement_no=20214906678966429555&invalid_time=2115-02-01+00%3A00%3A00&valid_time=2021-01-06+15%3A35%3A52&external_sign_no=1609918511&sign_type=MD5&status=NORMAL
        $da=file_get_contents("php://input");
       file_put_contents('./zhima_notify1.txt',json_encode($da));
       if($da){
          $data['partner_id']=$da['partner_id'];
          $data['agreement_no']=$da['agreement_no'];  //支付发送此参数
          $data['status']=$da['status'];
          $data['alipay_user_id']=$da['alipay_user_id'];
          $data['external_sign_no']=$da['external_sign_no'];//签约协议号
          $data['sign_time']=time();
       
          echo 'success';
           exit;
       
       }
    
    }
    
    //进行扣款
    
    public  function pay(){
        $agreement_no='20214906678966429555';
         $param['service']='alipay.acquire.createandpay';
 		  $param['partner']=config('config')['partner'];
          $param['_input_charset']='utf-8';
          $param['out_trade_no']=time();
          $param['subject']='测试';
          $param['notify_url']=config('questurl').'/api/alifreepay/paynotify';
          $param['product_code']='GENERAL_WITHHOLDING';
       // $param['product_code']='BARCODE_CODE_OFFLINE';
          $param['total_fee']='0.01';
          $param['agreement_info']='{"agreement_no":'.$agreement_no.'}';
          //$param['terminal_id']='xnbf';
         $key=config('config')['md5key'];
      
         $sign=SinParams($param,$key);
         $url='https://mapi.alipay.com/gateway.do?partner='.$param['partner'].'&product_code='.$param['product_code'].'&_input_charset=utf-8&notify_url='.$param['notify_url'].'&out_trade_no='.time().'&agreement_info='.$param['agreement_info'].'&subject=测试&total_fee='.$param['total_fee'].'&service='.$param['service'].'&sign='.$sign.'&sign_type=MD5';
         $res=http_get($url);
        $values = json_decode(json_encode(simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA)), true);  
        
        dump($values);
        
//       array(5) {
//   ["is_success"] => string(1) "T"
//   ["request"] => array(1) {
//     ["param"] => array(11) {
//       [0] => string(10) "1609920568"
//       [1] => string(16) "2088831484036885"
//       [2] => string(37) "{"agreement_no":20214906678966429555}"
//       [3] => string(5) "utf-8"
//       [4] => string(6) "测试"
//       [5] => string(27) "alipay.acquire.createandpay"
//       [6] => string(4) "0.01"
//       [7] => string(32) "c9393efb02b66790b70abcdeed1cc5c4"
//       [8] => string(19) "GENERAL_WITHHOLDING"
//       [9] => string(49) "********/api/alifreepay/paynotify"
//       [10] => string(3) "MD5"
//     }
//   }
//   ["response"] => array(1) {
//     ["alipay"] => array(7) {
//       ["buyer_logon_id"] => string(13) "734***@qq.com"
//       ["buyer_user_id"] => string(16) "2088802809584550"
//       ["gmt_payment"] => string(19) "2021-01-06 16:09:29"
//       ["out_trade_no"] => string(10) "1609920568"
//       ["result_code"] => string(25) "ORDER_SUCCESS_PAY_SUCCESS"
//       ["total_fee"] => string(4) "0.01"
//       ["trade_no"] => string(28) "2021010622001484551455234449"
//     }
//   }
//   ["sign"] => string(32) "23c901a8408fcdff8f6fca06b8a6a96c"
//   ["sign_type"] => string(3) "MD5"
// }
        
        
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PHP支付宝免签系统是一种基于PHP语言开发的支付宝支付系统。传统的支付宝接入需要商户自行向支付宝申请签约,并进行一系列的配置和接口对接,比较繁琐。而PHP支付宝免签系统则是通过直接调用支付宝支付接口实现支付功能,省去了商户签约的步骤,从而简化了支付宝支付的流程。 PHP支付宝免签系统的工作原理是通过调用支付宝的开放接口,实现与支付宝的交互。商户只需要在系统中配置好自己的支付宝账号和相关信息,然后调用相应的接口即可完成支付功能。系统会自动将订单信息提交给支付宝支付宝会返回支付页面给用户进行支付操作。支付成功后,支付宝会发送异步通知给商户服务器,商户服务器再进行订单处理。通过这种方式,商户无需签约支付宝,也能够方便地接入支付宝支付功能。 PHP支付宝免签系统的使用具有一定的优势。首先,简化了支付宝支付接入的流程,商户无需繁琐的签约和配置过程,只需进行简单的系统配置即可使用支付宝支付功能。其次,提高了支付安全性,系统直接与支付宝交互,保证了支付过程的可靠性和安全性。最后,提供了灵活的接口和参数设置,商户可以根据自己的需求自定义各种支付参数,实现个性化的支付体验。 综上所述,PHP支付宝免签系统是一种简化支付宝支付接入流程的解决方案,可以为商户提供简单、安全、灵活的支付服务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值