'http://wx.zhizhuchuxing.com/weixin/pay_success.html', 'fail' => 'http://wx.zhizhuchuxing.com/weixin/order_detail.html', 'order_detail' => 'http://wx.zhizhuchuxing.com/module/order/orderlist/getDetaile', 'update_order' => 'http://wx.zhizhuchuxing.com/module/order/order/updateOrderStatus' ); //获取参数 //获取订单号 if (!empty($_GET['order_id']) && $_GET['order_id'] !== false) { $order_id = $_GET['order_id']; } else { echo ""; exit; } //初始化日志 $logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log'); $log = Log::Init($logHandler, 15); //打印输出数组信息 function printf_info($data) { foreach ($data as $key => $value) { echo "$key : $value
"; } } //①、获取用户openid $tools = new JsApiPay(); $open_id = $tools->GetOpenid(); //支付 $jsApiParameters = pay($order_id,$url_arr,$pay_url,$open_id,$tools); //打log方法 function write_log1($result) { $dir = __DIR__ . '/Log/'; if (!is_dir($dir)) { mkdir($dir); } $filename = $dir . date("Y-m-d") . ".log"; file_put_contents($filename, date("Y-m-d H:i:s") . " " . $result . PHP_EOL, FILE_APPEND);//订单详细日志 } //判断支付支付 function CheckWeChatPay($order_id,$url_arr){ $order_result = WeChatShopOrderDetail($order_id,$url_arr); //已支付,跳转支付成功页面 if(!$order_result){ header('Location:' . $url_arr['success'] . '?order_id=' . $order_id); } //未支付 $price = (int)($order_result['price']*100); //测试价格 //$price = 1; //如果价格为0,修改订单状态 if($price == 0){ //1.修改订单状态 $data = array('order_id'=>$order_id); $update_order = http_request($url_arr['update_order'],$data); $update_order = json_decode($update_order,true); if(!$update_order['flag']){ echo ""; exit; } //2.跳转支付成功页面 header('Location:' . $url_arr['success'] . '?order_id=' . $order_id); } $prod_name = $order_result['prod_name']; return array( 'order_id' => $order_result['order_id'], 'price' => $price, 'prod_name' => $prod_name ); } //微信商城订单详情 function WeChatShopOrderDetail($order_id,$url_arr){ //获取订单详情 $data = array('order_id'=>$order_id, 'code'=>md5('zhizhuchuxing') ); $order_detail = http_request($url_arr['order_detail'],$data); $order_detail = json_decode($order_detail,true); //订单号无效 if(!$order_detail['flag']){ echo ""; exit; } //判断是否已支付 $order_detail = $order_detail['data']; if($order_detail['order_status'] == 145){ return array( 'order_id' => $order_detail['order_status'], 'price' => $order_detail['price'], 'prod_name' => $order_detail[0]['line_name'] ); }else{ return false; } } //支付方法 function pay($order_id,$url_arr,$pay_url,$open_id,$tools){ //验证支付 $order_info = CheckWeChatPay($order_id,$url_arr); //产品名 $prod_name = $order_info['prod_name']; $price = $order_info['price']; //支付 $input = new WxPayUnifiedOrder(); $SetBody = $prod_name . ": " . $order_id; $input->SetBody($SetBody); $SetOut_trade_no = $order_id . "-" . date("ymdHis"); //支付串号(商户单号) $input->SetOut_trade_no($SetOut_trade_no); $input->SetTotal_fee($price); $SetTime_start = date("YmdHis"); $input->SetTime_start($SetTime_start); $SetTime_expire = date("YmdHis", time() + 600); $input->SetTime_expire($SetTime_expire); $SetGoods_tag = "代金券"; $input->SetGoods_tag($SetGoods_tag); //打Log write_log1($pay_url); $input->SetNotify_url($pay_url); //回掉地址 $SetTrade_type = "JSAPI"; $input->SetTrade_type($SetTrade_type); $input->SetOpenid($open_id); //打Log write_log1($SetBody . "^" . $SetOut_trade_no . "^" . $price . "^" . $SetTime_start . "^" . $SetTime_expire . "^" . $SetGoods_tag . "^" . $pay_url . "^" . $SetTrade_type . "^" . $open_id); $order = WxPayApi::unifiedOrder($input, 15); //printf_info($order); $jsApiParameters = $tools->GetJsApiParameters($order); //print_r($jsApiParameters); //获取共享收货地址js函数参数 $editAddress = $tools->GetEditAddressParameters(); //打Log write_log1(json_encode($jsApiParameters)); return $jsApiParameters; } ?>