支付宝支付相关资料

支付宝小程序 所涉及的 支付宝支付 支付宝退款 流程
贴上详细代码 以供参考

支付宝支付

先下载官方的PHPSDK包 小程序官方SDK
先引入Vendor 然后如下配置
下载官方的sdk
控制器配置
在这里插入图片描述
支付宝的支付控制器

public function doalipay(){

        vendor('aop.AopClient');
        Vendor('aop.request.AlipayTradeCreateRequest');

        $aop = new \AopClient ();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->timestamp = date("Y-m-d H:i:s",time());
        $aop->appId = '2015555555555';
        $aop->method = 'alipay.trade.create';
        $aop->rsaPrivateKey = '商户私钥';
//        $aop->alipayrsaPublicKey =C("alipayrsaPublicKey");
        $aop->alipayrsaPublicKey='支付宝公钥';
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
            $request = new \AlipayTradeCreateRequest ();
        //商户外网可以访问的异步地址   这一步 必须要设置   官网没说  但是很重要
        $request->setNotifyUrl(U('Api/V6/Alipay/ali_notify', '', true, true));
        //请求的串  买家aliuser_id   没有的话  会报错哦!  比微信的要简单的多  就是这几个参数
        $content = array();
        $content['out_trade_no'] = $order_num;   //  商户订单号
        $content['total_amount'] = sprintf('%.2f',$allmoney);   //  订单总金额
        $content['subject'] = '户外租聘';   //  订单标题
        $content['buyer_id'] = I('aliuser_id');   //  买家aliuser_id  
        $content=json_encode($content);
        $request->setBizContent($content);
        $result = $aop->execute($request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";

        $resinfo['code'] = $result->$responseNode->code;
        if(!empty($resinfo['code'])&&$resinfo['code'] == 10000){
          
           $this->set_success('成功',$resinfo);
        }else{
            $this->set_error('失败',$resinfo);
        }
 }

支付宝的回调如何获取 参数 这个应该很简单 我顺口提一下 还应该验签 保证安全 结束回调 记得要返回
echo “success”;
} else {
echo “fail”;

  if(IS_POST) {
  			//获取参数
            $data = $_POST;
            //验签
            vendor('aop.AopClient');
            $aop = new \AopClient ();
            $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
            $aop->timestamp = date("Y-m-d H:i:s",time());
            $aop->appId = '00000000000';
            //$aop->notify_url = 'http://test.cnsunrun.com/sharelease/Api/V6/Alipay/ali_notify';
//        $aop->rsaPrivateKey =C("rsaPrivateKey");
            $aop->rsaPrivateKey = '';
//        $aop->alipayrsaPublicKey =C("alipayrsaPublicKey");
            $aop->alipayrsaPublicKey='';
            $aop->apiVersion = '1.0';
            $aop->signType = 'RSA2';
            $aop->postCharset='UTF-8';
            $aop->format='json';
            $flag = $aop->rsaCheckV1($data, NULL, "RSA2");
            if(!$flag || $data['trade_status'] != 'TRADE_SUCCESS'){
                echo "fail";exit;
            }

大家其实可以把参数 包装一下 然后 好看一些 。。

支付宝退款 和某信比 支付宝的文档简直是太良心了 而且参数也很少 没有乱七八糟的 某信的坑 简直吐了 连官方文档 里的接口名字都打乱了 各大社区去看才找到正确方法

  public function ali_refund($out_trade_no){
        vendor('aop.AopClient');
        Vendor('aop.request.AlipayTradeRefundRequest');

        $aop = new \AopClient ();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->timestamp = date("Y-m-d H:i:s",time());
        $aop->appId = '222222222222224';
        $aop->method = 'alipay.trade.refund';
        //$aop->notify_url = 'http://test.cnsunrun.com/sharelease/Api/V6/Alipay/ali_notify';
//        $aop->rsaPrivateKey =C("rsaPrivateKey");
        $aop->rsaPrivateKey = '';
//        $aop->alipayrsaPublicKey =C("alipayrsaPublicKey");
        $aop->alipayrsaPublicKey='';
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
        
        $request = new \AlipayTradeRefundRequest ();
        $content = array();
        $content['out_trade_no'] = $out_trade_no;   //  订单支付时传入的商户订单号,不能和 trade_no同时为空。
//        $content['refund_currency'] = 'whzp'.rand(10000,99999);   // 标识一次退款请求,同一笔交易多次退款需要保证唯一
//        $content['refund_currency'] = 'RMB';
        $content['refund_amount'] =sprintf('%.2f',$allmoney);;   //  订单总金额
        $content['refund_reason'] ='正常退款';   //  订单总金额


        $content=json_encode($content);
        $request->setBizContent($content);

        $result = $aop->execute ($request);

        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";

        $resinfo['code'] = $result->$responseNode->code;

        $resinfo['msg'] = $result->$responseNode->msg;
        $resinfo['out_trade_no'] = $result->$responseNode->out_trade_no;
        $resinfo['trade_no'] = $result->$responseNode->trade_no;
        $resinfo['sub_msg'] = $result->$responseNode->sub_msg;
        $resinfo['refund_amount'] = $result->$responseNode->refund_amount;
        if(!empty($resinfo['code'])&&$resinfo['code'] == 10000){
            return 1;
        }else{
        }
  }      

以上

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值