|
- <?php
- ini_set('date.timezone','Asia/Shanghai');
- //error_reporting(E_ERROR);
- require_once "../lib/WxPay.Api.php";
- require_once "WxPay.JsApiPay.php";
- require_once 'log.php';
- require_once '../../Common/Function.php';
-
- //初始化日志
- $logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
- $log = Log::Init($logHandler, 15);
-
- //打印输出数组信息
- function printf_info($data)
- {
- foreach($data as $key=>$value){
- echo "<font color='#00ff55;'>$key</font> : $value <br/>";
- }
- }
-
- //①、获取用户openid
- $tools = new JsApiPay();
- $openId = $tools->GetOpenid();
- //var_dump($_GET['orderid']);exit();
- if (!empty($_GET['orderid']) && $_GET['orderid'] !=='false'){
- $orderno=$_GET['orderid'];
- }else{
- echo "<script>alert('订单号有误')</script>";
- exit;
- }
-
- $url="http://xmwxc.zhizhuchuxing.cn/core/order_detail.asp?orderno=".$orderno;
- $result=http_request($url);
- wlog($openId."--".$orderno."--".$url."--".$result);
- $orderDetail=json_decode($result,true);
- //$money=$orderDetail['price']*100;
- $money=1;
- $name=$orderDetail['prod_name'];
- $order_status=$orderDetail['order_status'];
- if ($order_status !=='待支付'){
- //echo "<script>alert('不是待支付订单')</script>";
- //exit;
- }
- //$openId='oCVcbv1udkL4iZm-t1h8YMrMDSyU';
- //②、统一下单
- $input = new WxPayUnifiedOrder();
-
- $input->SetBody($name.": ".$orderno);
- //$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
- $input->SetOut_trade_no($orderno);
- $input->SetTotal_fee($money);
- $input->SetTime_start(date("YmdHis"));
-
- $input->SetTime_expire(date("YmdHis", time() + 600));
- $input->SetGoods_tag("代金券");
- $reurl=dirname("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])."/success_notify.php";
- wlog($reurl);
- $input->SetNotify_url($reurl);
- $input->SetTrade_type("JSAPI");
- $input->SetOpenid($openId);
- $order = WxPayApi::unifiedOrder($input);
- //echo '<font color="#f00"><b>统一下单支付单信息qwwww</b></font><br/>';
- //printf_info($order);
- $jsApiParameters = $tools->GetJsApiParameters($order);
- //print_r($jsApiParameters);
- //获取共享收货地址js函数参数
- $editAddress = $tools->GetEditAddressParameters();
-
- //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
- /**
- * 注意:
- * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
- * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
- * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
- */
- function wlog($result){
- file_put_contents('./order_detail.txt', date("Y-m-d H:i:s")." ".$result.PHP_EOL,FILE_APPEND);//订单详细日志
- }
- ?>
-
- <script type="text/javascript">
- window.onload = function(){
- if (typeof WeixinJSBridge == "undefined"){
- if( document.addEventListener ){
- document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
- }else if (document.attachEvent){
- document.attachEvent('WeixinJSBridgeReady', jsApiCall);
- document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
- }
- }else{
- jsApiCall();
- }
- };
- //调用微信JS api 支付
- function jsApiCall()
- {
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest',
- <?php echo $jsApiParameters; ?>,
- function(res){
- WeixinJSBridge.log(res.err_msg);
- if(res.err_msg =='get_brand_wcpay_request:ok'){
- var orderno=<?php echo $orderno ?>;
- alert('支付成功');
- location.href='http://xmwxc.zhizhuchuxing.cn/core/order_confirm1.asp?orderno='+orderno;
- }else if(res.err_msg =='get_brand_wcpay_request:cancel'){
-
- alert('取消支付');
- window.history.go(-1);
- }else{
- alert('支付失败');
- window.history.go(-1);
- }
- }
- );
- }
-
- function callpay()
- {
- if (typeof WeixinJSBridge == "undefined"){
- if( document.addEventListener ){
- document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
- }else if (document.attachEvent){
- document.attachEvent('WeixinJSBridgeReady', jsApiCall);
- document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
- }
- }else{
- jsApiCall();
- }
- }
- </script>
-
|