<?php

if (!defined('IN_OELOVE')) {
exit('OElove[OEPHP] Access Denied');
}
$weixin_incfile = BASE_ROOT."source/conf/weixin.inc.php";
if (file_exists($weixin_incfile)) {
require_once($weixin_incfile);
}
require_once(BASE_ROOT."api/netpay/weixinpay/lib/WxPay.Config.php");
require_once(BASE_ROOT."api/netpay/weixinpay/lib/WxPay.Api.php");
require_once(BASE_ROOT."api/netpay/weixinpay/WxPay.NativePay.php");
require_once(BASE_ROOT."api/netpay/weixinpay/lib/WxPay.Notify.php");
class wxh5payWModel extends OE {
public function submit($orderdata) {
if (empty($orderdata)) {
die("order error");
}
$notify = new NativePay();
$input = new WxPayUnifiedOrder();
$input->SetBody($orderdata['title']);
$input->SetAttach($orderdata['title']);
$input->SetOut_trade_no($orderdata['paynum']);
$input->SetTotal_fee($orderdata['amount']*100);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis",time() +6000));
$input->SetNotify_url(OE::$cfg['siteurl']."notify/weixin_h5pay.php");
$input->SetTrade_type("MWEB");
$input->SetProduct_id($orderdata['paynum']);
$input->SetSpbill_create_ip(XRequest::getClientIp());
$scene_info = '{"h5_info": {"type":"Wap","wap_url": "https://pay.qq.com","wap_name": "腾讯充值"}}';
$input->SetH5Scene($scene_info);
$result = $notify->GetPayUrl($input);
if (defined("WEIXIN_DEBUG")) {
if (WEIXIN_DEBUG == 1) {
print_r($result);
}
}
$h5_url = $result["mweb_url"];
$html = "<html>\n".
"<head>\n".
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n".
"</head>\n".
"<body>\n".
"<form name='wxh5_pay' id='wxh5_pay' action='{$h5_url}' method='post'>\n".
"</form>\n".
"</body>\n".
"<script>document.wxh5_pay.submit();</script>\n".
"</html>\n";
echo $html;
die();
}
public function h5CallBack() {
$notify = new H5NotifyCallBack();
$notify_xml = $notify->Handle(true,false);
return $notify_xml;
}
}
class H5NotifyCallBack extends WxPayNotify {
public function unifiedorder($openId,$order_data) {
$input = new WxPayUnifiedOrder();
$input->SetBody($order_data['title']);
$input->SetAttach($order_data['title']);
$input->SetOut_trade_no($order_data['paynum']);
$input->SetTotal_fee($order_data['amount']*100);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis",time() +6000));
$input->SetNotify_url(OE::$cfg['siteurl']."notifiy/weixin_h5pay.php");
$input->SetTrade_type("NATIVE");
$input->SetOpenid($openId);
$input->SetProduct_id($order_data['paynum']);
$result = WxPayApi::unifiedOrder($input);
XLogic::writeTxtLog(json_encode($result)." unified","wxh5pay");
return $result;
}
public function NotifyProcess($data,&$msg) {
if (is_array($data)) {
$log_array = array(
"out_trade_no"=>$data['out_trade_no'],
"transaction_id"=>$data['transaction_id'],
"result_code"=>$data['result_code'],
"return_code"=>$data['return_code'],
);
$log_cont = "callback:".json_encode($log_array);
XLogic::writeTxtLog($log_cont,"wxh5pay");
}
if (!array_key_exists("openid",$data) ||!array_key_exists("out_trade_no",$data)) {
$msg = "回调数据异常";
XLogic::writeTxtLog($msg,"wxh5pay");
return false;
}
$openid = $data["openid"];
$out_trade_no = $data["out_trade_no"];
$transaction_id = $data['transaction_id'];
$result_code = $data['result_code'];
$return_code = $data['return_code'];
if (empty($out_trade_no)) {
$msg = "订单号错误";
XLogic::writeTxtLog($msg,"wxh5pay");
return false;
}
if ($result_code == "SUCCESS"&&$return_code['SUCCESS'] &&true === XValid::isSpChar($out_trade_no)) {
$payment_data = M("payorder","im")->getOrderData($out_trade_no);
if (empty($payment_data)) {
$msg = "订单信息错误";
XLogic::writeTxtLog($msg,"wxh5pay");
return false;
}
else {
if ($payment_data['paystatus'] == 0 ||$payment_data['paystatus'] == 11) {
$notic_array = array(
"sdkid"=>997,
"dealnum"=>$transaction_id,
"flag"=>1,
"bankid"=>"微信支付(H5)",
);
$notic_res = M("payorder","im")->doCallBack($out_trade_no,$notic_array);
return true;
}
else {
XLogic::writeTxtLog("回调执行：订单重复执行{$out_trade_no}","wxh5pay");
return true;
}
}
}
else {
$msg = "回调数据异常";
XLogic::writeTxtLog($msg,"wxh5pay");
return false;
}
}
}
?>
