2 Star 6 Fork 3

康师傅 / thinkphp5-app支付

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

app-pay

APP 支付

安装

composer require kang/app-pay

示例

  • 支付宝

    // 测试数据开始
    $subject = "iPhone";
    $total_amount = "5688";
    $out_trade_no = "201612172344562";      // 订单号,不超过64位
    // 测试数据结束
    
    // 业务参数
    $bizContentArr = array(
        "timeout_express"       =>  "30m",      // 30分钟 —— 该笔订单允许的最晚付款时间,逾期将关闭交易。该参数数值不接受小数点
        "product_code"		    =>	"QUICK_MSECURITY_PAY",  // 固定值,销售产品码
        "total_amount"          =>  $total_amount,
        "subject"               =>  $subject,
        "out_trade_no"          =>  $out_trade_no,
    );
    
    // 公共参数
    $data = array(
        "charset"               =>  "UTF-8",
        "timestamp"             =>  date("Y-m-d H:i:s",time()),
        "biz_content"           =>  $bizContentArr
    );
    
    $alipay = new \kang\appPay\alipay\Alipay();
    $sign = $alipay->request($data);
    echo $sign;
  • 微信

    // 测试数据开始,由客户端传递
    $body = "iPhone";
    $out_trade_no = "201609241165665169";
    $total_fee = "15";
    $spbill_create_ip = "115.28.95.67";
    // 测试数据结束
    
    $data = array(
        "body"              =>  $body,
        "out_trade_no"      =>  $out_trade_no,
        "total_fee"         =>  $total_fee,
        "spbill_create_ip"  =>  $spbill_create_ip
    );
    
    // 实例化签名类
    $pay = new \kang\appPay\wepay\WePay();
    $response = $pay->request($data);
    
    // 解析XML数据
    $xml = new \kang\appPay\wepay\XmlTransfer();
    $response = $xml->xml2Array($response);
    
    if (!empty($response))
    {
        if ("FAIL" == $response["return_code"])
        {
            $ret = array(
                'status'		=>	'FAIL',
                'msg'	        =>	$response["return_msg"]
            );
            echo json_encode($ret);
        }
        else
        {
            if ("SUCCESS" == $response["result_code"]) {
            	$resign = array(
    	            "appid"         =>  $response["appid"],
    	            "partnerid"     =>  $response["mch_id"],
    	            "prepayid"      =>  $response["prepay_id"],
    	            "noncestr"      =>  $response["nonce_str"],
    	            "timestamp"     =>  time(),
    	            "package"       =>  "Sign=WXPay"
    	        );
    	        $encpt = new \kang\appPay\wepay\WeEncryption();
    	        $sign = $encpt->signature($resign);
    	        $resign["sign"] = $sign;
    	        echo json_encode($resign);
            }
            else
            {
            	$ret = array(
                    'status'		=>	'FAIL',
                    'msg'	        =>	$response["err_code_des"]
                );
            	echo json_encode($ret);
            }
        }
    }

Comments ( 0 )

Sign in for post a comment

About

Thinkphp5 支付宝、微信、app支付等 spread retract
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
1
https://gitee.com/getkang/thinkphp5app_payment.git
git@gitee.com:getkang/thinkphp5app_payment.git
getkang
thinkphp5app_payment
thinkphp5-app支付
master

Search