接上两篇支付宝支付和微信支付,下面我这边讲的是QQ支付:
下面简单介绍下QQApp支付后端的实现(这边是用php实现的):
一、 一些琐碎的申请和设置的方式就不说明了,这些微信上都有说,但相比于支付宝吗,微信和QQ的文档相比差之千里,太简单太low了,并且没有SDKDEMO,但小伙伴们不用担心,下面是我这边封装好的一个类,可供直接使用,都有标注说明
一、封装好的QQ调用类库:(这个不管是app支付还是其他支付都可共用)
<?php
class qqAppPay
{
const API_URL_PREFIX = 'https://qpay.qq.com';
const UNIFIEDORDER_URL = "/cgi-bin/pay/qpay_unified_order.cgi";
const ORDERQUERY_URL = "/cgi-bin/pay/qpay_order_query.cgi";
const CLOSEORDER_URL = "/cgi-bin/pay/qpay_close_order.cgi";
private $appid;
private $mch_id ='1452072601';
private $nonce_str;
private $sign;
private $body;
private $out_trade_no;
private $total_fee;
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;
}
public function unifiedOrder( $params ){
$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;
}
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($