const APPID = 'xxx'; const MCHID = 'xxx'; const KEY = 'xxx'; const APPSECRET = 'xxx';
require_once "./phpcms/plugin/weixinpay/lib/WxPay.Api.php";
require_once "./phpcms/plugin/weixinpay/example/WxPay.NativePay.php";
require_once './phpcms/plugin/weixinpay/example/log.php';
$input = new WxPayUnifiedOrder();
$input->SetBody('预订'.$product_info['name'].'订单');
$input->SetAttach('预订'.$product_info['name'].'订单');
$input->SetOut_trade_no($order_info['orderno']);
$input->SetTotal_fee($order_info['payprice'] * 100);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("");
$input->SetNotify_url("http://www.ayuanduanzu.com/wxpay/notify.php"); // 地址是外网能访问的,且不能包含参数
$input->SetTrade_type("NATIVE");
$input->SetProduct_id($product_info['id']);
$notify = new NativePay();
$result = $notify->GetPayUrl($input);
$code_url = $result["code_url"];
<img alt="扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data={urlencode($code_url)}" style="width:150px;height:150px;"/>
include_once "../phpcms/base.php";
// 处理回调数据
error_reporting(E_ERROR);
require_once "../phpcms/plugin/weixinpay/lib/WxPay.Api.php";
require_once '../phpcms/plugin/weixinpay/lib/WxPay.Notify.php';
require_once '../phpcms/plugin/weixinpay/example/log.php';
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
class PayNotifyCallBack extends WxPayNotify
//查询订单
public function Queryorder($transaction_id)
{
$input = new WxPayOrderQuery();
$input->SetTransaction_id($transaction_id);
$result = WxPayApi::orderQuery($input);
Log::DEBUG("query:" . json_encode($result));
if(array_key_exists("return_code", $result)
&& array_key_exists("result_code", $result)
&& $result["return_code"] == "SUCCESS"
&& $result["result_code"] == "SUCCESS")
{
return true;
}
return false;
}
//重写回调处理函数
public function NotifyProcess($data, &$msg)
{
Log::DEBUG("call back:" . json_encode($data));
$notfiyOutput = array();
if(!array_key_exists("transaction_id", $data)){
$msg = "输入参数不正确";
return false;
}
//查询订单,判断订单真实性
if(!$this->Queryorder($data["transaction_id"])){
$msg = "订单查询失败";
return false;
}
return true;
}
Log::DEBUG("begin notify");
$notify = new PayNotifyCallBack();
$ilog_db = pc_base::load_model('ilog_model');
$order_db = pc_base::load_model('order_model');
$postXml = $GLOBALS["HTTP_RAW_POST_DATA"];
$postArr = xmlToArray($postXml);
// 查询是否支付成功
$r = $notify->Queryorder($postArr['transaction_id']);
if ($r) {
// 获取订单信息
$order_info = $order_db->get_one(array('orderno'=>$postArr['out_trade_no']));
if ($order_info['pay_status'] != '1') {
$data['pay_status'] = '1';
$data['pay_type'] = 'weixinpay';
$data['pay_code'] = $postArr['transaction_id'];
$data['paytime'] = time();
$data['order_status']= 3; // 已支付
$order_db->update($data,array('orderno'=>$postArr['out_trade_no']));
}
?>
$GLOBALS["HTTP_RAW_POST_DATA"];
{
"appid": "wxed7996e9ad58345d",
"attach": "u9884u8ba2u5bbfu8fc1u00b7u592au53e4u91ccu7f8eu5f0fu5957u623fu8ba2u5355",
"bank_type": "CFT",
"cash_fee": "1",
"fee_type": "CNY",
"is_subscribe": "Y",
"mch_id": "1283301801",
"nonce_str": "20xn5e0lbk2u1u6pes2uonape2sdyfs4",
"openid": "oR8C7wsknwVELIRrzTlZX2eONWeY",
"out_trade_no": "2016091455521024608",
"result_code": "SUCCESS",
"return_code": "SUCCESS",
"sign": "95C2C532D095E7BF7588522C579758C4",
"time_end": "20160914135518",
"total_fee": "1",
"trade_type": "NATIVE",
"transaction_id": "4009602001201609143926590576"
}
// 检测是否支付成功
$(document).ready(function () {
setInterval("ajaxstatus()", 3000);
function ajaxstatus() {
var orderno = $("#out_trade_no").val();
if (orderno != 0) {
$.ajax({
url: "?m=home&c=order&a=ajax",
type: "GET",
dataType:"json",
data: {
todo: 'ajaxCheckWxPay',
orderno: orderno,
},
success: function (json) {
if (json.status == 1) { //订单状态为1表示支付成功
layer.msg('支付成功',{icon:1,time: 2000},function(){
window.location.href = "?m=home&c=order&a=payDone&orderno="+json.info['orderno'];
});
// window.location.href = "wxScanSuccessUrl.action"; //页面跳转
}
}
});
}
}
* 作用:array转xml
*/
function arrayToXml($arr)
$xml = "<xml>";
foreach ($arr as $key=>$val)
{
if (is_numeric($val))
{
$xml.="<".$key.">".$val."</".$key.">";
}
else
$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
}
$xml.="</xml>";
return $xml;
* 作用:将xml转为array
*/
function xmlToArray($xml)
{
//将XML转为array
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $array_data;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有