实现APP支付QQ,微信,支付宝三方的后端服务------php实现QQAPP支付

本文档介绍了如何使用PHP实现QQ应用内支付的后端服务,包括封装好的QQ支付类库,以及如何调用相关类方法处理订单。同时提到了微信支付的简要内容,并提供了PHP实现支付宝APP支付的链接。
摘要由CSDN通过智能技术生成

接上两篇支付宝支付和微信支付,下面我这边讲的是QQ支付:

下面简单介绍下QQApp支付后端的实现(这边是用php实现的):
一、 一些琐碎的申请和设置的方式就不说明了,这些微信上都有说,但相比于支付宝吗,微信和QQ的文档相比差之千里,太简单太low了,并且没有SDKDEMO,但小伙伴们不用担心,下面是我这边封装好的一个类,可供直接使用,都有标注说明
一、封装好的QQ调用类库:(这个不管是app支付还是其他支付都可共用)
<?php
/**
 * Created by PhpStorm.
 * User: wyb
 * Date: 2017/3/29
 * Time: 10:17
 */
class qqAppPay
{
   
    //接口API URL前缀

    const API_URL_PREFIX = 'https://qpay.qq.com';
    //下单地址URL
    const UNIFIEDORDER_URL = "/cgi-bin/pay/qpay_unified_order.cgi";
    //查询订单URL
    const ORDERQUERY_URL = "/cgi-bin/pay/qpay_order_query.cgi";
    //关闭订单URL
    const CLOSEORDER_URL = "/cgi-bin/pay/qpay_close_order.cgi";
    //应用号ID
    private $appid;
    //商户号
    private $mch_id ='1452072601';
    //随机字符串
    private $nonce_str;
    //签名
    private $sign;
    //商品描述
    private $body;
    //商户订单号
    private $out_trade_no;
    //支付总金额
    private $total_fee;
    //终端IP
    private $spbill_create_ip;
    //支付结果回调通知地址
    private $notify_url ='http://apps.ifeimo.com/Sysj218/Recharge/qqpayNotify'; //不能写固定于该文件内,后续变更为外部传入
    //交易类型
    private $trade_type;
    //支付密钥
    private $key='F1DAB8538EC979F99C062F3BE308062C';
    // 表单提交字符集编码
    public $postCharset = "UTF-8";
    //签名类型
    public $signType = "HMAC-SHA1";
    //证书路径
    private $SSLCERT_PATH;
    private $SSLKEY_PATH;
    //所有参数
    private $params = array();
    public function __construct($wxappid)
    {
   
        $this->appid = $wxappid;
//        $this->mch_id = $mch_id;
//        $this->notify_url = $notify_url;
//        $this->key = $key;
    }
    /**
     * 下单方法
     * @param   $params 下单参数
     */
    public function unifiedOrder( $params ){
   
//        $this->body = $params['body'];
//        $this->out_trade_no = $params['out_trade_no'];
//        $this->total_fee = $params['total_fee'];
//        $this->trade_type = $params['trade_type'];
//        $this->nonce_str = $this->genRandomString();
        $this->spbill_create_ip = $_SERVER['REMOTE_ADDR'];
        $this->params['appid'] = $this->appid;
        $this->params['mch_id'] = $this->mch_id;
        $this->params['nonce_str'] = $this->nonce_str = $this->genRandomString();
        $this->params['body'] = $this->body = $params['body'];
        $this->params['out_trade_no'] = $this->out_trade_no = $params['out_trade_no'];
        $this->params['total_fee'] = $this->total_fee = $params['total_fee'];
        $this->params['spbill_create_ip'] = $this->spbill_create_ip;
        $this->params['notify_url'] = $params['notify_url'] ? $params['notify_url'] : $this->notify_url;
        $this->params['trade_type'] = $this->trade_type = $params['trade_type'];


        //获取签名数据
        $this->sign = $this->MakeSign( $this->params );
        $this->params['sign'] = $this->sign;
        $xml = $this->data_to_xml($this->params);
        $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::UNIFIEDORDER_URL);
        if( !$response ){
            return false;
        }
        $result = $this->xml_to_data( $response );
        if( !empty($result['result_code']) && !empty($result['err_code']) ){
            $result['err_msg'] = $this->error_code( $result['err_code'] );
        }

        return $result;
    }
    /**
     * 查询订单信息
     * @param $out_trade_no     订单号
     * @return array
     */
    public function orderQuery( $out_trade_no ){
   
        $this->params['appid'] = $this->appid;
        $this->params['mch_id'] = $this->mch_id;
        $this->params['nonce_str'] = $this->genRandomString();
        $this->params['out_trade_no'] = $out_trade_no;
        //获取签名数据
        $this->sign = $this->MakeSign( $this->params );
        $this->params['sign'] = $this->sign;
        $xml = $this->data_to_xml($this->params);
        $response = $this->postXmlCurl($
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值