提交 4b24d83f 编写于 作者: J jianbo

调整支付代码,解决和其他插件使用腾讯官方支付示例代码引起的冲突。

上级 2cfa3197
此差异已折叠。
......@@ -3,7 +3,7 @@
* 配置账号信息
*/
class WxPayConfig
class RAM_WxPayConfig
{
//=======【基本信息设置】=====================================
//
......
......@@ -12,7 +12,7 @@ require_once( REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/wxpay/WxPay.Excepti
* @author widyhu
*
*/
class WxPayDataBase
class RAM_WxPayDataBase
{
protected $values = array();
......@@ -47,14 +47,14 @@ class WxPayDataBase
/**
* 输出xml字符
* @throws WxPayException
* @throws RAM_WxPayException
**/
public function ToXml()
{
if(!is_array($this->values)
|| count($this->values) <= 0)
{
throw new WxPayException("数组数据异常!");
throw new RAM_WxPayException("数组数据异常!");
}
$xml = "<xml>";
......@@ -73,12 +73,12 @@ class WxPayDataBase
/**
* 将xml转为array
* @param string $xml
* @throws WxPayException
* @throws RAM_WxPayException
*/
public function FromXml($xml)
{
if(!$xml){
throw new WxPayException("xml数据异常!");
throw new RAM_WxPayException("xml数据异常!");
}
//将XML转为array
//禁止引用外部xml实体
......@@ -114,7 +114,7 @@ class WxPayDataBase
ksort($this->values);
$string = $this->ToUrlParams();
//签名步骤二:在string后加入KEY
$string = $string . "&key=".WxPayConfig::get_key();
$string = $string . "&key=".RAM_WxPayConfig::get_key();
//签名步骤三:MD5加密
$string = md5($string);
//签名步骤四:所有字符转为大写
......@@ -137,7 +137,7 @@ class WxPayDataBase
* @author widyhu
*
*/
class WxPayResults extends WxPayDataBase
class RAM_WxPayResults extends RAM_WxPayDataBase
{
/**
*
......@@ -147,14 +147,14 @@ class WxPayResults extends WxPayDataBase
{
//fix异常
if(!$this->IsSignSet()){
throw new WxPayException("签名错误!");
throw new RAM_WxPayException("签名错误!");
}
$sign = $this->MakeSign();
if($this->GetSign() == $sign){
return true;
}
throw new WxPayException("签名错误!");
throw new RAM_WxPayException("签名错误!");
}
/**
......@@ -197,7 +197,7 @@ class WxPayResults extends WxPayDataBase
/**
* 将xml转为array
* @param string $xml
* @throws WxPayException
* @throws RAM_WxPayException
*/
public static function Init($xml)
{
......@@ -218,7 +218,7 @@ class WxPayResults extends WxPayDataBase
* @author widyhu
*
*/
class WxPayNotifyReply extends WxPayDataBase
class RAM_WxPayNotifyReply extends RAM_WxPayDataBase
{
/**
*
......@@ -278,7 +278,7 @@ class WxPayNotifyReply extends WxPayDataBase
* @author widyhu
*
*/
class WxPayUnifiedOrder extends WxPayDataBase
class RAM_WxPayUnifiedOrder extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -753,7 +753,7 @@ class WxPayUnifiedOrder extends WxPayDataBase
* @author widyhu
*
*/
class WxPayOrderQuery extends WxPayDataBase
class RAM_WxPayOrderQuery extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -891,7 +891,7 @@ class WxPayOrderQuery extends WxPayDataBase
* @author widyhu
*
*/
class WxPayCloseOrder extends WxPayDataBase
class RAM_WxPayCloseOrder extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -1003,7 +1003,7 @@ class WxPayCloseOrder extends WxPayDataBase
* @author widyhu
*
*/
class WxPayRefund extends WxPayDataBase
class RAM_WxPayRefund extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -1296,7 +1296,7 @@ class WxPayRefund extends WxPayDataBase
* @author widyhu
*
*/
class WxPayRefundQuery extends WxPayDataBase
class RAM_WxPayRefundQuery extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -1511,7 +1511,7 @@ class WxPayRefundQuery extends WxPayDataBase
* @author widyhu
*
*/
class WxPayDownloadBill extends WxPayDataBase
class RAM_WxPayDownloadBill extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -1674,7 +1674,7 @@ class WxPayDownloadBill extends WxPayDataBase
* @author widyhu
*
*/
class WxPayReport extends WxPayDataBase
class RAM_WxPayReport extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -2046,7 +2046,7 @@ class WxPayReport extends WxPayDataBase
* @author widyhu
*
*/
class WxPayShortUrl extends WxPayDataBase
class RAM_WxPayShortUrl extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -2158,7 +2158,7 @@ class WxPayShortUrl extends WxPayDataBase
* @author widyhu
*
*/
class WxPayMicroPay extends WxPayDataBase
class RAM_WxPayMicroPay extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -2555,7 +2555,7 @@ class WxPayMicroPay extends WxPayDataBase
* @author widyhu
*
*/
class WxPayReverse extends WxPayDataBase
class RAM_WxPayReverse extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -2693,7 +2693,7 @@ class WxPayReverse extends WxPayDataBase
* @author widyhu
*
*/
class WxPayJsApiPay extends WxPayDataBase
class RAM_WxPayJsApiPay extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......@@ -2854,7 +2854,7 @@ class WxPayJsApiPay extends WxPayDataBase
* @author widyhu
*
*/
class WxPayBizPayUrl extends WxPayDataBase
class RAM_WxPayBizPayUrl extends RAM_WxPayDataBase
{
/**
* 设置微信分配的公众账号ID
......
......@@ -5,7 +5,7 @@
* @author widyhu
*
*/
class WxPayException extends Exception {
class RAM_WxPayException extends Exception {
public function errorMessage()
{
return $this->getMessage();
......
......@@ -12,7 +12,7 @@ require_once( REST_API_TO_MINIPROGRAM_PLUGIN_DIR . 'includes/wxpay/WxPay.Api.php
* @author widy
*
*/
class JsApiPay
class RAM_JsApiPay
{
/**
*
......@@ -60,7 +60,7 @@ class JsApiPay
*
* 获取jsapi支付的参数
* @param array $UnifiedOrderResult 统一支付接口返回的数据
* @throws WxPayException
* @throws RAM_WxPayException
*
* @return json数据,可直接填入js函数作为参数
*/
......@@ -70,13 +70,13 @@ class JsApiPay
|| !array_key_exists("prepay_id", $UnifiedOrderResult)
|| $UnifiedOrderResult['prepay_id'] == "")
{
throw new WxPayException("参数错误");
throw new RAM_WxPayException("参数错误");
}
$jsapi = new WxPayJsApiPay();
$jsapi = new RAM_WxPayJsApiPay();
$jsapi->SetAppid($UnifiedOrderResult["appid"]);
$timeStamp = time();
$jsapi->SetTimeStamp("$timeStamp");
$jsapi->SetNonceStr(WxPayApi::getNonceStr());
$jsapi->SetNonceStr(RAM_WxPayApi::getNonceStr());
$jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
$jsapi->SetSignType("MD5");
$jsapi->SetPaySign($jsapi->MakeSign());
......@@ -98,7 +98,7 @@ class JsApiPay
//初始化curl
$ch = curl_init();
$curlVersion = curl_version();
$ua = "WXPaySDK/0.0.5 (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['version']." ".WxPayConfig::MCHID;
$ua = "WXPaySDK/0.0.5 (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['version']." ".RAM_WxPayConfig::MCHID;
//设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout);
......@@ -108,10 +108,10 @@ class JsApiPay
curl_setopt($ch,CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
&& WxPayConfig::CURL_PROXY_PORT != 0){
curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
if(RAM_WxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
&& RAM_WxPayConfig::CURL_PROXY_PORT != 0){
curl_setopt($ch,CURLOPT_PROXY, RAM_WxPayConfig::CURL_PROXY_HOST);
curl_setopt($ch,CURLOPT_PROXYPORT, RAM_WxPayConfig::CURL_PROXY_PORT);
}
//运行curl,结果以jason形式返回
$res = curl_exec($ch);
......@@ -154,7 +154,7 @@ class JsApiPay
{
$getData = $this->data;
$data = array();
$data["appid"] = WxPayConfig::APPID;
$data["appid"] = RAM_WxPayConfig::APPID;
$data["url"] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$time = time();
$data["timestamp"] = "$time";
......@@ -168,7 +168,7 @@ class JsApiPay
"addrSign" => $addrSign,
"signType" => "sha1",
"scope" => "jsapi_address",
"appId" => WxPayConfig::APPID,
"appId" => RAM_WxPayConfig::APPID,
"timeStamp" => $data["timestamp"],
"nonceStr" => $data["noncestr"]
);
......@@ -185,7 +185,7 @@ class JsApiPay
*/
private function __CreateOauthUrlForCode($redirectUrl)
{
$urlObj["appid"] = WxPayConfig::APPID;
$urlObj["appid"] = RAM_WxPayConfig::APPID;
$urlObj["redirect_uri"] = "$redirectUrl";
$urlObj["response_type"] = "code";
$urlObj["scope"] = "snsapi_base";
......@@ -203,8 +203,8 @@ class JsApiPay
*/
private function __CreateOauthUrlForOpenid($code)
{
$urlObj["appid"] = WxPayConfig::APPID;
$urlObj["secret"] = WxPayConfig::APPSECRET;
$urlObj["appid"] = RAM_WxPayConfig::APPID;
$urlObj["secret"] = RAM_WxPayConfig::APPSECRET;
$urlObj["code"] = $code;
$urlObj["grant_type"] = "authorization_code";
$bizString = $this->ToUrlParams($urlObj);
......
......@@ -5,7 +5,7 @@
* @author widyhu
*
*/
class WxPayNotify extends WxPayNotifyReply
class RAM_WxPayNotify extends RAM_WxPayNotifyReply
{
/**
*
......
<?php
//以下为日志
interface ILogHandler
{
public function write($msg);
}
class CLogFileHandler implements ILogHandler
{
private $handle = null;
public function __construct($file = '')
{
$this->handle = fopen($file,'a');
}
public function write($msg)
{
fwrite($this->handle, $msg, 4096);
}
public function __destruct()
{
fclose($this->handle);
}
}
class Log
{
private $handler = null;
private $level = 15;
private static $instance = null;
private function __construct(){}
private function __clone(){}
public static function Init($handler = null,$level = 15)
{
if(!self::$instance instanceof self)
{
self::$instance = new self();
self::$instance->__setHandle($handler);
self::$instance->__setLevel($level);
}
return self::$instance;
}
private function __setHandle($handler){
$this->handler = $handler;
}
private function __setLevel($level)
{
$this->level = $level;
}
public static function DEBUG($msg)
{
self::$instance->write(1, $msg);
}
public static function WARN($msg)
{
self::$instance->write(4, $msg);
}
public static function ERROR($msg)
{
$debugInfo = debug_backtrace();
$stack = "[";
foreach($debugInfo as $key => $val){
if(array_key_exists("file", $val)){
$stack .= ",file:" . $val["file"];
}
if(array_key_exists("line", $val)){
$stack .= ",line:" . $val["line"];
}
if(array_key_exists("function", $val)){
$stack .= ",function:" . $val["function"];
}
}
$stack .= "]";
self::$instance->write(8, $stack . $msg);
}
public static function INFO($msg)
{
self::$instance->write(2, $msg);
}
private function getLevelStr($level)
{
switch ($level)
{
case 1:
return 'debug';
break;
case 2:
return 'info';
break;
case 4:
return 'warn';
break;
case 8:
return 'error';
break;
default:
}
}
protected function write($level,$msg)
{
if(($level & $this->level) == $level )
{
$msg = '['.date('Y-m-d H:i:s').']['.$this->getLevelStr($level).'] '.$msg."\n";
$this->handler->write($msg);
}
}
}
<?php
ini_set('date.timezone','Asia/Shanghai');
//error_reporting(E_ERROR);
require_once "../lib/WxPay.Api.php";
require_once "WxPay.NativePay.php";
require_once 'log.php';
//模式一
/**
* 流程:
* 1、组装包含支付信息的url,生成二维码
* 2、用户扫描二维码,进行支付
* 3、确定支付之后,微信服务器会回调预先配置的回调地址,在【微信开放平台-微信支付-支付配置】中进行配置
* 4、在接到回调通知之后,用户进行统一下单支付,并返回支付信息以完成支付(见:native_notify.php)
* 5、支付完成之后,微信服务器会通知支付成功
* 6、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
*/
$notify = new NativePay();
$url1 = $notify->GetPrePayUrl("123456789");
//模式二
/**
* 流程:
* 1、调用统一下单,取得code_url,生成二维码
* 2、用户扫描二维码,进行支付
* 3、支付完成之后,微信服务器会通知支付成功
* 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
*/
$input = new WxPayUnifiedOrder();
$input->SetBody("test");
$input->SetAttach("test");
$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
$input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
$input->SetTrade_type("NATIVE");
$input->SetProduct_id("123456789");
$result = $notify->GetPayUrl($input);
$url2 = $result["code_url"];
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>微信支付样例-退款</title>
</head>
<body>
<div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式一</div><br/>
<img alt="模式一扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data=<?php echo urlencode($url1);?>" style="width:150px;height:150px;"/>
<br/><br/><br/>
<div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式二</div><br/>
<img alt="模式二扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data=<?php echo urlencode($url2);?>" style="width:150px;height:150px;"/>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册