Browse Source

no message

panghu 8 tháng trước cách đây
mục cha
commit
512afa2ac7

+ 55 - 0
app/Http/Controllers/Api/NotifyController.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace App\Http\Controllers\Api;
+
+
+
+use App\Http\Controllers\ApiController;
+use App\Servers\OrderServer;
+use App\Servers\WeixinServer;
+
+class NotifyController extends ApiController
+{
+
+
+    public function __construct()
+    {
+
+    }
+
+
+    /**
+     * 订单支付回调
+     */
+    function orderWx()
+    {
+        $xml = file_get_contents('php://input');
+//        $xml = request()->rawBody();
+        $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
+//        file_put_contents('order_wx_pay.txt', json_encode($data));
+
+        $sign = WeixinServer::creatServer()->verifyCer($data);
+        if ($sign != $data['sign']) {
+            $xml = '<xml>
+  <return_code><![CDATA[SUCCESS]]></return_code>
+  <return_msg><![CDATA[OK]]></return_msg>
+</xml>';
+//            exit($xml);
+
+            return $xml;
+        }
+
+        if ($data['result_code'] == 'SUCCESS' && $data['return_code'] == 'SUCCESS') {
+            OrderServer::creatServer()->NotifyPay(1,$data['out_trade_no'], $data['transaction_id'], $data['total_fee'] / 100, $data);
+        }
+        $xml = '<xml>
+  <return_code><![CDATA[SUCCESS]]></return_code>
+  <return_msg><![CDATA[OK]]></return_msg>
+</xml>';
+//        exit($xml);
+        return $xml;
+    }
+
+
+}

+ 34 - 205
app/Http/Controllers/Api/OrderController.php

@@ -5,10 +5,14 @@ namespace App\Http\Controllers\Api;
 
 
 
 
 use App\Http\Controllers\ApiController;
 use App\Http\Controllers\ApiController;
+use App\Models\Order;
+use App\Models\OrderItem;
 use App\Servers\CommonServer;
 use App\Servers\CommonServer;
 use App\Servers\OrderServer;
 use App\Servers\OrderServer;
 use App\Servers\RedisDataServer;
 use App\Servers\RedisDataServer;
 use App\Servers\ShoppingCartServer;
 use App\Servers\ShoppingCartServer;
+use App\Servers\ShopServer;
+use App\Servers\WeixinServer;
 use Carbon\Carbon;
 use Carbon\Carbon;
 use Illuminate\Validation\Rules\In;
 use Illuminate\Validation\Rules\In;
 
 
@@ -51,7 +55,7 @@ class OrderController extends ApiController
         $m_id = $this->getMemberId();//用户id
         $m_id = $this->getMemberId();//用户id
         $commonServer = CommonServer::creatServer();
         $commonServer = CommonServer::creatServer();
         $shop_id = $commonServer->filtrationStr('shop_id');//商家id
         $shop_id = $commonServer->filtrationStr('shop_id');//商家id
-        $order_type = $commonServer->filtrationStr('$order_type',1);//订单类型 1堂食订单 2打包订单
+        $order_type = $commonServer->filtrationStr('order_type',1);//订单类型 1堂食订单 2打包订单
         $table_number = $commonServer->filtrationStr('table_number');//桌号
         $table_number = $commonServer->filtrationStr('table_number');//桌号
         $diner_number = $commonServer->filtrationStr('diner_number');//就餐人数
         $diner_number = $commonServer->filtrationStr('diner_number');//就餐人数
         $note = $commonServer->filtrationStr('note');//备注
         $note = $commonServer->filtrationStr('note');//备注
@@ -64,7 +68,10 @@ class OrderController extends ApiController
         if (empty($diner_number) || $table_number < 0) return $this->apiResponseError('就餐人数错误');
         if (empty($diner_number) || $table_number < 0) return $this->apiResponseError('就餐人数错误');
         if (!empty($note) && mb_strlen($note) > 30 ) return $this->apiResponseError('备注最大30');
         if (!empty($note) && mb_strlen($note) > 30 ) return $this->apiResponseError('备注最大30');
 
 
-
+        //获取商家信息
+        $shop = ShopServer::creatServer()->getShopInfo($shop_id);
+        if (empty($shop)) return $this->apiResponseError('该商家不存在');
+        if ($shop->{'status'} != 1) return $this->apiResponseError('商家闭店休息中');
         //获取购买的商品信息
         //获取购买的商品信息
         $goods = ShoppingCartServer::creatServer()->getShoppingList($m_id,$shop_id);
         $goods = ShoppingCartServer::creatServer()->getShoppingList($m_id,$shop_id);
         if (count($goods['goods_list']) <= 0) {
         if (count($goods['goods_list']) <= 0) {
@@ -90,37 +97,6 @@ class OrderController extends ApiController
     }
     }
 
 
 
 
-    /**
-     * 获取订单支付信息
-     * @return \Illuminate\Http\JsonResponse
-     */
-    function getOrderPayInfo()
-    {
-        $m_id = $this->getMemberId();//用户id
-        $commonServer = CommonServer::creatServer();
-        $order_id = $commonServer->filtrationStr('order_id');//订单id
-        if (empty($order_id)) {
-            return $this->apiResponseError('缺少必要参数');
-        }
-        $member = Member::where('id', $m_id)->select(['id', 'money'])->first();
-        if (empty($member)) {
-            return $this->apiResponseError('会员信息错误');
-        }
-        $order_info = Order::where('id', $order_id)
-            ->where('m_id', $m_id)
-            ->where('order_status', 1)
-            ->select(['id', 'order_status', 'order_money','pay_money','coupon_money', 'order_sn', 'shop_id','created_at'])
-            ->first();
-        if (empty($order_info)) {
-            return $this->apiResponseError('订单已失效');
-        }
-        $order_info->{'member_money'} = $member['money'];//用户余额
-        //订单过期时间
-        $end_time = config('order.order_repeal_time', 10) * 60;
-        $order_info->{'time'} = strtotime($order_info->{'created_at'}) + $end_time;
-        return $this->apiResponseSuccess('获取数据成功', $order_info);
-    }
-
     /**
     /**
      * 支付订单
      * 支付订单
      */
      */
@@ -129,7 +105,7 @@ class OrderController extends ApiController
         $m_id = $this->getMemberId();//用户id
         $m_id = $this->getMemberId();//用户id
         $commonServer = CommonServer::creatServer();
         $commonServer = CommonServer::creatServer();
         $order_id = $commonServer->filtrationStr('order_id');//订单id
         $order_id = $commonServer->filtrationStr('order_id');//订单id
-        $pay_type = $commonServer->filtrationStr('pay_type',1);//支付方式 1微信 2支付宝 3余额支付
+        $pay_type = $commonServer->filtrationStr('pay_type',1);//支付方式 1微信 2支付宝
         $system_type = request()->input('system_type',2);//1微信h5 2微信小程序 3qq小程序
         $system_type = request()->input('system_type',2);//1微信h5 2微信小程序 3qq小程序
 
 
         if (empty($order_id)) return $this->apiResponseError('请选择订单');
         if (empty($order_id)) return $this->apiResponseError('请选择订单');
@@ -144,11 +120,10 @@ class OrderController extends ApiController
             return $this->apiResponseError('订单已失效');
             return $this->apiResponseError('订单已失效');
         }
         }
 
 
-        //获取商家状态
-        $shop_status = Shop::where('id', $order_info['shop_id'])->value('status');
-        if ($shop_status != 1) {
-            return $this->apiResponseError('商家已闭店');
-        }
+        //获取商家信息
+        $shop = ShopServer::creatServer()->getShopInfo($order_info->{'shop_id'});
+        if (empty($shop)) return $this->apiResponseError('该商家不存在');
+        if ($shop->{'status'} != 1) return $this->apiResponseError('商家已闭店');
         //定义返回参数
         //定义返回参数
         $data = ['pay_status' => false, 'wx_pay' => [], 'zfb_pay' => []];
         $data = ['pay_status' => false, 'wx_pay' => [], 'zfb_pay' => []];
         if($pay_type == 1) {
         if($pay_type == 1) {
@@ -162,22 +137,6 @@ class OrderController extends ApiController
             $data['wx_pay'] = $wx_pay;
             $data['wx_pay'] = $wx_pay;
         }elseif ($pay_type == 2) {
         }elseif ($pay_type == 2) {
             $data['zfb_pay'] = [];
             $data['zfb_pay'] = [];
-        }else{//余额支付
-
-            $member = Member::where('id', $m_id)->select(['id', 'money'])->first();
-            if (empty($member)) {
-                return $this->apiResponseError('会员信息错误');
-            }
-            if ($member->{'money'} < $order_info->{'pay_money'}) {
-                return $this->apiResponseError('余额不足');
-            }
-
-            //余额扣款
-            $ret = OrderServer::creatServer()->balancePay($order_info);
-            if (empty($ret)) {
-                return $this->apiResponseError('余额支付失败');
-            }
-            $data['pay_status'] = true;
         }
         }
 
 
         return $this->apiResponseSuccess('成功', $data);
         return $this->apiResponseSuccess('成功', $data);
@@ -192,33 +151,25 @@ class OrderController extends ApiController
     {
     {
         $m_id = $this->getMemberId();//用户id
         $m_id = $this->getMemberId();//用户id
         $commonServer = CommonServer::creatServer();
         $commonServer = CommonServer::creatServer();
-        $status = $commonServer->filtrationStr('status',-1);//状态 0全部 1待支付 2待接单 3配送中 4待评价 5退款/撤销
+        $status = $commonServer->filtrationStr('status',-1);//状态 0全部1=>'待支付',2=>'制作中',3=>'已完成',4=>'已取消',5=>'退款',
+        $shop_id = $commonServer->filtrationStr('shop_id');//商家id
+        if (empty($shop_id)) return $this->apiResponseError('商家错误');
 
 
-        $where = [['o.m_id',$m_id], ['o.is_del',0]];
+        $where = [['m_id',$m_id], ['is_del',0], ['shop_id',$shop_id]];
 
 
-        $list = Order::from('order as o')
-            ->leftJoin('shops as s','s.id','=','o.shop_id')
-            ->where($where)
+        $list = Order::where($where)
             ->where(function ($q) use ($status){
             ->where(function ($q) use ($status){
-                if ($status == 1){
-                    $q->where('o.order_status',1);
-                }elseif ($status == 2){
-                    $q->where('o.order_status',2);
-                }elseif ($status == 3){
-                    $q->whereIn('o.order_status',[4,5,6]);
-                }elseif ($status == 4){
-                    $q->where('o.order_status',7);
-                    $q->where('o.is_comment',0);
-                }elseif ($status == 5){
-                    $q->whereIn('o.order_status',[3,8,9,10]);
+                if (in_array($status,[1,2,3,4,5])){
+                    $q->where('order_status',$status);
                 }
                 }
             })
             })
-            ->select(['o.id','o.order_sn','o.order_status','o.pay_money','o.is_comment','o.goods_number','o.created_at','o.shop_id','s.shop_name','s.shop_logo'])
+            ->select(['id','order_sn','order_status','pay_money','goods_number','created_at','shop_id'])
             ->orderBy('o.id','desc')
             ->orderBy('o.id','desc')
             ->paginate(10);
             ->paginate(10);
         foreach ($list as $value){
         foreach ($list as $value){
-            $value->{'refund_status'} = OrderDetails::where('order_id',$value->{'id'})->value('refund_status');
-            $value->{'shop_name'} = $commonServer->truncateChineseString($value->{'shop_name'},16);
+
+            $shop_info = ShopServer::creatServer()->getShopInfo($value->{'shop_id'});
+            $value->{'shop_name'} = $commonServer->truncateChineseString($shop_info['shop_name'],16);
             $value->{'item'} = OrderItem::where('order_id',$value->{'id'})->select(['goods_name','goods_img'])->orderBy('id','asc')->get();
             $value->{'item'} = OrderItem::where('order_id',$value->{'id'})->select(['goods_name','goods_img'])->orderBy('id','asc')->get();
             $value->initializeModel();
             $value->initializeModel();
         }
         }
@@ -239,82 +190,26 @@ class OrderController extends ApiController
         $m_id = $this->getMemberId();//用户id
         $m_id = $this->getMemberId();//用户id
         $commonServer = CommonServer::creatServer();
         $commonServer = CommonServer::creatServer();
         $order_id = $commonServer->filtrationStr('order_id');//订单id
         $order_id = $commonServer->filtrationStr('order_id');//订单id
-        $refund_msg = $commonServer->filtrationStr('refund_msg','');//退款原因
         if (empty($order_id) || !is_numeric($order_id)) {
         if (empty($order_id) || !is_numeric($order_id)) {
             return $this->apiResponseError('请选择订单');
             return $this->apiResponseError('请选择订单');
         }
         }
-        if (empty($refund_msg)) return $this->apiResponseError('请选择原因');
 
 
         $order_info = Order::where('m_id', $m_id)
         $order_info = Order::where('m_id', $m_id)
             ->where('id', $order_id)
             ->where('id', $order_id)
             ->where('is_del',0)
             ->where('is_del',0)
-            ->select(['id','order_sn','m_id','operate_id','school_id', 'time', 'order_type','order_status','pay_money','pay_type','pay_code', 'shop_id','coupon_id'])
+            ->select(['id','order_sn','m_id', 'order_type','order_status','shop_id'])
             ->first();
             ->first();
         if (empty($order_info)) return $this->apiResponseError('订单信息错误');
         if (empty($order_info)) return $this->apiResponseError('订单信息错误');
 
 
-        if (!in_array($order_info['order_status'], [2,4])) {
+        if ($order_info->{'order_status'} != 1) {
             return $this->apiResponseError('当前订单不能取消');
             return $this->apiResponseError('当前订单不能取消');
         }
         }
 
 
-        //获取需要的配送时间
-        $date = date('Y-m-d H:i:s');
-        $current_time = Carbon::parse($date, config('app.timezone'))->format('Y-m-d H:i:s');
-        //获取需要的配送时间
-        $delivery_time = ShopServer::creatServer()->getShopDeliveryTime($order_info->{'shop_id'});
-        $time = Carbon::parse($order_info->{'time'}, config('app.timezone'))->subMinutes($delivery_time + 30)->format('Y-m-d H:i:s');
-
-        if ($order_info->{'order_status'} == 2 || $current_time < $time){//订单状态为待接单或者当前时间小于预定送达时间 - ($delivery_time + 30)
-            $ret = OrderServer::creatServer()->refundPay($order_info,'用户取消订单,原因:'.$refund_msg);
-            if (empty($ret)) {
-                return $this->apiResponseError('退款失败');
-            }
-
-            $refund_sn = $ret['refund_sn'];
-            $refund_money = $ret['refund_money'];
-            Order::where('id', $order_info->{'id'})->update(['order_status' => 8]);
-            OrderDetails::where('order_id', $order_info->{'id'})->update(['refund_status' => 2,'refund_sn'=>$refund_sn,'refund_money'=>$refund_money,'refund_msg'=>$refund_msg]);
-            //添加记录
-            OrderRecordServer::creatServer()->writeRecord($order_info->{'id'},$order_info->{'shop_id'},0,0,'用户发起订单退款,退款完成,原因:'.$refund_msg);
-
-            //回退优惠卷
-            CouponServer::creatServer()->backCoupon($order_info->{'m_id'},$order_info->{'coupon_id'});
-            //获取订单商品,商品不是无限库存需要回退库存
-            $goods = OrderItem::from('order_item as i')
-                ->leftJoin('goods as g','g.id','=','i.goods_id')
-                ->where('i.order_id',$order_id)
-                ->select(['i.goods_number','i.goods_id','i.goods_spec_id','i.seckill_money','g.is_infinite','g.stock'])
-                ->get();
-            foreach ($goods as $value){
-                if ($value->{'is_infinite'} != 1){//回退库存
-                    Goods::where('id',$value['goods_id'])->increment('stock',$value['goods_number']);
-                }
-                if ($value->{'seckill_money'} > 0){
-                    $key_name = 'seckill_'.$value['goods_id'];
-
-                    RedisDataServer::creatServer()->addOneQueue($key_name, 1);
-                }
-            }
-            //投递用户订单统计任务
-            JobServer::creatServer()->sendMemberOrderTotal($order_info->{'m_id'},$order_info->{'school_id'},1,$order_info->{'created_at'},0,$order_info->{'pay_money'});
-            //投递商户订单统计任务
-            JobServer::creatServer()->sendShopOrderTotal($order_info->{'shop_id'},$order_info->{'school_id'},1,$order_info->{'created_at'},0,$order_info->{'pay_money'});
-            JobServer::creatServer()->sendSchoolOrderTotal($order_info->{'school_id'},1,$order_info->{'created_at'},0,$order_info->{'pay_money'});
-
-            return $this->apiResponseSuccess('退款成功');
-        }else{//已接单需要商家同意
-            $ret = Order::where('id', $order_info->{'id'})->update(['order_status' => 8]);
-            OrderDetails::where('order_id', $order_info->{'id'})->update(['refund_status' => 1,'refund_msg'=>$refund_msg]);
-            if (empty($ret)) {
-                return $this->apiResponseError('申请退款失败');
-            } else {
-                //添加记录
-                OrderRecordServer::creatServer()->writeRecord($order_info->{'id'},$order_info->{'shop_id'},0,0,'用户发起订单退款,等待商家确认,原因:'.$refund_msg);
-                //投递打印任务
-                JobServer::creatServer()->cancelOrderPrintJob($order_info->{'id'},$order_info->{'shop_id'},1);
-                return $this->apiResponseSuccess('等待商家同意中');
-            }
+        $res = Order::where('id', $order_info->{'id'})->update(['order_status' => 4]);
+        if (!$res){
+            return $this->apiResponseError('操作失败');
         }
         }
-
+        return $this->apiResponseSuccess('操作成功');
     }
     }
 
 
 
 
@@ -329,89 +224,23 @@ class OrderController extends ApiController
 
 
         if (empty($order_id)) return $this->apiResponseError('请选择订单');
         if (empty($order_id)) return $this->apiResponseError('请选择订单');
 
 
-        $where = [['o.m_id',$m_id], ['o.is_del',0], ['o.id',$order_id]];
+        $where = [['m_id',$m_id], ['is_del',0], ['id',$order_id]];
 
 
         $order = Order::from('order as o')
         $order = Order::from('order as o')
-            ->leftJoin('order_address as a','a.order_id','=','o.id')
-            ->leftJoin('order_details as d','d.order_id','=','o.id')
             ->where($where)
             ->where($where)
-            ->select(['o.id','o.order_sn','o.time','o.pay_type','o.m_id','o.note','o.order_status','o.pay_money','o.is_comment','o.goods_number','o.coupon_money','o.shop_id','o.created_at','d.refund_status','d.pack_price','d.delivery_money','d.finish_time','d.finish_image','a.school_id','a.dorm_id','a.consignee','a.phone as consignee_tel','a.address'])
+            ->select(['id','order_sn','pay_type','m_id','note','order_status','pay_money','goods_number','shop_id','created_at','pack_price','table_number','diner_number','number'])
             ->first();
             ->first();
         if (empty($order)) return $this->apiResponseError('订单不存在');
         if (empty($order)) return $this->apiResponseError('订单不存在');
-        $order->{'school_name'} = School::where('id',$order->{'school_id'})->value('school_name');
-        $order->{'dorm_name'} = SchoolDorm::where('id',$order->{'dorm_id'})->value('name');
-        $order->{'shop'} = Shop::where('id',$order->{'shop_id'})->select(['shop_name','shop_logo','shop_phone'])->first();
+        $order->{'shop'} = ShopServer::creatServer()->getShopInfo($order->{'shop_id'});
         $order->{'item'} = OrderItem::where('order_id',$order_id)
         $order->{'item'} = OrderItem::where('order_id',$order_id)
             ->select(['goods_name','goods_img','goods_attr','goods_number','goods_price'])
             ->select(['goods_name','goods_img','goods_attr','goods_number','goods_price'])
             ->orderBy('id','asc')
             ->orderBy('id','asc')
             ->get();
             ->get();
 
 
-        //获取最新的骑手id
-        $rider_id = OrderRecord::where('order_id',$order_id)->where('rider_id','>',0)->orderBy('id','desc')->value('rider_id');
-        if (!empty($rider_id)){
-            $rider = Rider::where('id',$rider_id)->select(['rider_name','phone'])->first();
-        }else{
-            $rider['rider_name'] = '';
-            $rider['phone'] = '';
-        }
-        $order->{'rider'} = $rider;
-
         $order->initializeModel();
         $order->initializeModel();
 
 
         return $this->apiResponseSuccess('成功', $order);
         return $this->apiResponseSuccess('成功', $order);
     }
     }
 
 
 
 
-    /**
-     * 修改收货地址
-     */
-    function updateAddress()
-    {
-        $m_id = $this->getMemberId();//用户id
-        $commonServer = CommonServer::creatServer();
-        $order_id = $commonServer->filtrationStr('order_id');//订单id
-        $address_id = $commonServer->filtrationStr('address_id', '');//地址id
-        if (empty($order_id) || !is_numeric($order_id)) {
-            return $this->apiResponseError('缺少必要参数');
-        }
-        if (empty($address_id)) {
-            return $this->apiResponseError('请输入新地址信息');
-        }
-
-        $where = [['m_id', $m_id], ['id',$order_id], ['is_del', 0]];
-        $order = Order::where($where)
-            ->select(['id', 'order_sn', 'order_status', 'm_id'])
-            ->orderBy('id', 'desc')
-            ->first();
-        if (empty($order)) {
-            return $this->apiResponseError('订单信息错误');
-        }
-        if ($order->{'order_status'} > 2) {
-            return $this->apiResponseError('订单状态错误');
-        }
-        //获取地址信息
-        $address_info = MemberAddress::where('m_id',$m_id)
-            ->where('id',$address_id)
-            ->where('is_del',0)
-            ->select(['id','phone','school_id','dorm_id','consignee','address'])
-            ->first();
-        if (empty($address_info)) {
-            return $this->apiResponseError('地址信息错误');
-        }
-
-        $info = OrderAddress::where('m_id',$m_id)->where('order_id',$order_id)->select(['id','school_id'])->first();
-        //判断收货地址是否在一个学校
-        if ($info->{'school_id'} != $address_info->{'school_id'}) {
-            return $this->apiResponseError('收货地址与该订单不在同一学校');
-        }
-
-        $res = OrderServer::creatServer()->saveAddress($m_id,$order_id, $address_info);
-
-        if (!$res) {
-            return $this->apiResponseError('修改失败');
-        }
-        //添加记录
-        OrderRecordServer::creatServer()->writeRecord($order_id,0,0,0,'用户修改收货地址');
-        return $this->apiResponseSuccess('修改成功');
-    }
 }
 }

+ 1 - 0
app/Http/Middleware/MemberAuth.php

@@ -22,6 +22,7 @@ class MemberAuth
     {
     {
         //不需要验证的路由
         //不需要验证的路由
         $noAuth = [
         $noAuth = [
+            'notify.order_wx',//订单微信支付回调
         ];
         ];
 
 
 //        echo '这里是请求穿越阶段,也就是请求处理前';
 //        echo '这里是请求穿越阶段,也就是请求处理前';

+ 4 - 6
app/Models/Order.php

@@ -79,15 +79,13 @@ class Order extends Model
      */
      */
     function initializeModel(){
     function initializeModel(){
         if($this->{'order_status'}!==null){
         if($this->{'order_status'}!==null){
-            if ($this->{'order_status'} == 8){
-                $this->{'order_status_str'}=empty($this->refundStatusEnum[$this->{'refund_status'}])?'无':$this->refundStatusEnum[$this->{'refund_status'}];
-            }else{
-                $this->{'order_status_str'}=empty($this->orderStatusEnum[$this->{'order_status'}])?'无':$this->orderStatusEnum[$this->{'order_status'}];
-            }
+            $this->{'order_status_str'}=empty($this->orderStatusEnum[$this->{'order_status'}])?'无':$this->orderStatusEnum[$this->{'order_status'}];
         }
         }
         if($this->{'pay_type'}!==null){
         if($this->{'pay_type'}!==null){
             $this->{'pay_type_str'}=empty($this->payTypeEnum[$this->{'pay_type'}])?'无':$this->payTypeEnum[$this->{'pay_type'}];
             $this->{'pay_type_str'}=empty($this->payTypeEnum[$this->{'pay_type'}])?'无':$this->payTypeEnum[$this->{'pay_type'}];
-
+        }
+        if($this->{'order_type'}!==null){
+            $this->{'order_type_str'}=empty($this->orderTypeEnum[$this->{'order_type'}])?'无':$this->orderTypeEnum[$this->{'order_type'}];
         }
         }
     }
     }
 
 

+ 47 - 0
app/Servers/ShopServer.php

@@ -0,0 +1,47 @@
+<?php
+
+
+namespace App\Servers;
+
+
+
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 商家管理
+ */
+class ShopServer
+{
+
+    static private $server = null;
+
+
+
+    private function __construct()
+    {
+
+    }
+
+    /**
+     * 创建对象
+     * @return ShopServer
+     */
+    static function creatServer()
+    {
+        if (empty(self::$server)) self::$server = new ShopServer();
+        return self::$server;
+    }
+
+    /**
+     * 获取店铺详情
+     * @param $shop_id
+     * @return string[]
+     */
+    function getShopInfo($shop_id){
+         //$status 1正常 2闭店
+        $info = ['shop_name' => '','shop_logo'=>'','shop_phone'=>'','status'=>1];
+        return $info;
+    }
+
+
+}

+ 467 - 0
app/Servers/WeixinServer.php

@@ -0,0 +1,467 @@
+<?php
+
+
+namespace App\Servers;
+
+
+use App\Models\ErrorRecord;
+use App\Servers\weixin\Unifiedorder;
+
+class WeixinServer
+{
+    static private $server = null;
+    public $mch_id = '';
+    public $private_key = '';
+    public $cert_file = '';
+    public $key_file = '';
+
+    public $appid = '';
+    public $appsecret = '';
+
+    public $appletId = '';
+    public $appletKey = '';
+
+    function __construct()
+    {
+//        $this->mch_id=env('WX_MCH_ID','');
+//        $this->private_key=env('WX_PRIVATE_KEY','');
+//        $this->appid=env('WX_APPID','');
+//        $this->appsecret=env('WX_APPSECRET','');
+//        $this->cert_file=env('WX_CERT_FILE','');
+//        $this->key_file=env('WX_KEY_FILE','');
+//        $this->appletId=env('APPLET_ID','');
+//        $this->appletKey=env('APPLET_KEY','');
+        $this->mch_id=config('weixin.mch_id','');
+        $this->private_key=config('weixin.private_key','');
+        $this->appid=config('weixin.app_id','');
+        $this->appsecret=config('weixin.app_secret','');
+        $this->cert_file=config('weixin.cert_file','');
+        $this->key_file=config('weixin.key_file','');
+        $this->appletId=config('weixin.applet_id','');
+        $this->appletKey=config('weixin.applet_key','');
+    }
+
+
+    /**
+     * 创建对象
+     * @return WeixinServer
+     */
+    static function creatServer()
+    {
+        if (empty(self::$server)) self::$server = new WeixinServer();
+        return self::$server;
+    }
+
+
+
+    /**
+     * 小程序code获取openid等信息
+     * @param $code
+     * @param $invite_code
+     * @return array|false
+     */
+    function getAppletsOpenId($code){
+
+        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->appletId}&secret={$this->appletKey}&js_code={$code}&grant_type=authorization_code";
+        $result = $this->sendRequest($url);
+        $result = json_decode($result, true);
+        if ( !isset($result['openid'])) {//成功返回信息
+            return ['code'=>0,'msg'=>$result['errmsg']];
+        } else {
+            return $result;
+        }
+    }
+
+
+    /**
+     * 获取小程序码
+     * @param $page  //页面路径
+     * @param $scene  //携带参数
+     */
+    function getAppletCode($page,$scene){
+        $access_token = $this->getAccessToken(2);
+
+        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$access_token}";
+        $data['page'] = $page;
+        $data['scene'] = $scene;
+        $data['check_path'] = false;
+        $data['width'] = 300;
+//        $data['env_version'] = 'trial';//要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
+        $result = $this->sendRequest($url,'post',$data);
+
+        return $result;
+    }
+
+    /**
+     * 获取 access_token
+     * @return bool
+     */
+    protected function getAccessToken($type = 1)
+    {
+        if($type == 1){
+            $key = 'vouchername';
+            $appId = $this->appid;
+            $appsecret = $this->appsecret;
+        }else{
+            $key = 'applet_voucher';
+            $appId = $this->appletId;
+            $appsecret = $this->appletKey;
+        }
+        $data = RedisDataServer::creatServer()->getData($key, 'json');
+        if (empty($data) || $data['endtime'] < time()) {
+            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appsecret}";
+            $result = $this->sendRequest($url);
+            $result = json_decode($result, true);
+//            $bey = Cache::set('vouchername', array('access_token' => $result['access_token'], 'endtime' => time() + 7000), 7000);
+            if ( isset($result['access_token'])) {
+                RedisDataServer::creatServer()->setData($key, array('access_token' => $result['access_token'], 'endtime' => time() + 1800), 'json',1800);
+                return $result['access_token'];
+            } else {
+                return false;
+            }
+        } else {
+            return $data['access_token'];
+        }
+    }
+
+    /**
+     * 获取js授权信息
+     * @return mixed
+     */
+    function getJsConfig($url = '')
+    {
+        $hash = '';
+        $chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz';
+        $max = strlen($chars) - 1;
+        for ($i = 0; $i < 16; $i++) {
+            $hash .= $chars[mt_rand(0, $max)];
+        }
+        $data['noncestr'] = $hash;
+        $data['jsapi_ticket'] = $this->getJsTicket();
+        $data['timestamp'] = time();
+        if (empty($url)) {
+            $data['url'] = $this->getServerUrl();
+        } else {
+            $data['url'] = $url;
+        }
+        ksort($data);
+        $str = '';
+        foreach ($data as $key => $val) {
+            $str .= '&';
+            $str .= $key . '=' . $val;
+        }
+        $str = mb_substr($str, 1);
+        $data['appId'] = $this->appid;
+        $data['signature'] = sha1($str);
+        unset($data['jsapi_ticket']);
+        return $data;
+    }
+
+    /**
+     * 获取当前连接
+     * @return string
+     */
+    function getServerUrl()
+    {
+//        $http_host=request()->header('host');
+//        $data=request()->all();
+        return urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+//        return 'http://'.$http_host. '?' . http_build_query($data);;
+    }
+
+    /**
+     * 获取Js调用凭证
+     * @return bool
+     */
+    function getJsTicket()
+    {
+//        $data = Cache::get('js_ticket');
+        $data = RedisDataServer::creatServer()->getData('js_ticket', 'json');
+        if (empty($data) || $data['endtime'] < time()) {
+            $access_token = $this->getAccessToken();
+            $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$access_token}&type=jsapi";
+            $result = $this->sendRequest($url);
+            $result = json_decode($result, true);
+            if ($result['errcode'] == 0) {
+                //file_put_contents($this->js_ticket,serialize(array('access_token'=>$result['access_token'],'endtime'=>time()+7000)));
+//                Cache::set('js_ticket', array('access_token' => $result['ticket'], 'endtime' => time() + 7000), 7000);
+                RedisDataServer::creatServer()->setData('js_ticket', array('access_token' => $result['ticket'], 'endtime' => time() + 7000), 'json',7000);
+                return $result['ticket'];
+            }
+            return false;
+        } else {
+            return $data['access_token'];
+        }
+    }
+
+
+    /**
+     * 文本内容安全识别
+     * @param $openid
+     * @param $content
+     * @return bool
+     */
+    function msgSecCheck($openid,$content)
+    {
+
+        $access_token = $this->getAccessToken(2);
+        $url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token;
+
+        $conf = array(
+            'content' => $content,
+            'version' => 2,
+            'openid' => $openid,
+            'scene' => 2,
+
+        );
+//        var_dump($conf);
+        $result = $this->http_post_request($url,json_encode($conf, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+//        $result = json_decode($result, true);
+//var_dump($result);
+        if ($result['errcode'] != 0) {
+            return false;
+        }elseif ($result['result']['label'] != 100) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    /**
+     * 图片和视频内容安全识别
+     * @param $openid
+     * @param $media_url
+     * @param $media_type
+     * @return false|mixed
+     */
+    function mediaCheckAsync($openid,$media_url,$media_type=1)
+    {
+        $access_token = $this->getAccessToken(2);
+//        var_dump($access_token);
+        $url = 'https://api.weixin.qq.com/wxa/media_check_async?access_token='.$access_token;
+
+        $conf = array(
+            'media_url' => $media_url,
+            'media_type' => $media_type,
+            'version' => 2,
+            'openid' => $openid,
+            'scene' => 1,
+        );
+        $result = $this->http_post_request($url,json_encode($conf, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+//        var_dump($result);
+        if ($result['errcode'] != 0) {
+            return false;
+        }else{
+            return $result['trace_id'];
+        }
+    }
+
+
+    /**
+     * 微信签名
+     */
+    function wxSign($data, $keys)
+    {
+        ksort($data);
+        $str = '';
+        foreach ($data as $key => $val) {
+            if ($val) {
+                if ($str != '') $str .= '&';
+                $str .= "{$key}={$val}";
+            }
+        }
+        $str .= '&key=' . $keys;
+        $sign = strtoupper(MD5($str));
+        return $sign;
+    }
+
+
+    /**
+     * @param $url
+     * @param string $type 请求方式
+     * @param string $data 数据 数组格式
+     * @return mixed
+     */
+    protected function sendRequest($url, $type = 'get', $data = '')
+    {
+
+        $ch = curl_init();
+        if ($type == 'get' && $data) {
+            $url = $url . '?' . http_build_query($data);
+        }
+        curl_setopt($ch, CURLOPT_URL, $url); //设置访问路径
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //设置可以返回字符串
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        $head = array('User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36');
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
+        if ($type == 'post') {
+            curl_setopt($ch, CURLOPT_POST, TRUE);//post请求
+            $data = json_encode($data, JSON_UNESCAPED_UNICODE);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置传递的参数
+        }
+        $request = curl_exec($ch);
+        curl_close($ch);
+        return $request;
+    }
+
+    public function http_post_request($url, $jsonStr)
+    {
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_POST, 1);// 发送一个常规的Post请求
+        curl_setopt($ch, CURLOPT_URL, $url);// 要访问的地址
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测
+        curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+                'Content-Type: application/json;charset=UTF-8',
+                'Content-Length: ' . strlen($jsonStr)
+            )
+        );
+
+        $response = curl_exec($ch);
+        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+        $http_error = curl_error($ch);
+        curl_close($ch);
+
+        $response = json_decode($response, 1);
+//var_dump($response);
+        return $response;
+    }
+
+    /**
+     * JS支付签名
+     * @param $order_sn
+     * @param $total_fee
+     * @param $notify_url
+     * @param $body
+     * @param $wx_openid
+     * @return bool
+     */
+    public function wxJsPay($order_sn, $total_fee, $notify_url, $body, $wx_openid = '')
+    {
+//        $is_test=env('TEST_SERVE',false);
+        $is_test=config('weixin.test_serve',false);
+        if($is_test) {
+//            PayServer::creatServer()->NotifyPay($order_sn, '147258369', $total_fee, ['data'=>'测试']);//暂时测试直接走回调
+            $total_fee = 0.01;
+        }
+        $conf = array(
+            'appid' => $this->appletId,
+            'mch_id' => $this->mch_id,
+            'notify_url' => $notify_url,
+            'openid' => $wx_openid,
+            'out_trade_no' => $order_sn,
+            'total_fee' => $total_fee * 100,
+            'trade_type' => 'JSAPI',
+            'body' => $body,
+
+        );
+//        var_dump($conf);
+        $order = new Unifiedorder($conf);
+        $request = $order->getOrder($this->private_key);
+//        var_dump($request);
+        if ($request['code'] == 1) {
+            $datas["appId"] = $request['data']['appid'];
+            $datas["nonceStr"] = $order->getNonceStr();
+            $datas["package"] = "prepay_id={$request['data']['prepay_id']}";
+            $datas["signType"] = 'MD5';
+            $datas["timeStamp"] = time();
+            $s = $order->wxSign($datas, $this->private_key);
+            $datas["paySign"] = $s;
+            return $datas;
+        } else {
+            return false;
+        }
+    }
+
+
+
+    /**
+     * 微信验签
+     * @param $data
+     * @return string
+     */
+    function verifyCer($data)
+    {
+        if (isset($data['sign'])) unset($data['sign']);
+        $conf = array(
+            'appid' => $this->appletId,
+            'mch_id' => $this->mch_id,
+        );
+        $order = new Unifiedorder($conf);
+        $sign = $order->wxSign($data, $this->private_key);
+        return $sign;
+    }
+
+    /**
+     * 微信退款
+     * @param $total_fee
+     * @param $out_trade_no
+     * @param string $body
+     * @param int $order_money
+     * @return array
+     */
+
+    function wxPayRefund($out_trade_no, $total_fee,  $body = '',$order_money=0)
+    {
+//        $is_test=env('TEST_SERVE',false);
+        $is_test=config('weixin.test_serve',false);
+//        dd($is_test);
+        if($is_test){
+            $total_fee = 0.01;
+            $order_money = 0.01;
+        }
+        $conf = array(
+            'appid' => $this->appletId,
+            'mch_id' => $this->mch_id,
+            'out_trade_no' => $out_trade_no,
+            'out_refund_no' => 'T'.$out_trade_no.time(),
+            'total_fee' => $order_money * 100,
+            'refund_fee' => $total_fee * 100,
+            'refund_desc' => $body
+        );
+        $order = new Unifiedorder($conf, ['cert_file' => base_path($this->cert_file), 'key_file' =>  base_path($this->key_file)]);
+        $request = $order->wxPayRefund($this->private_key);
+//        var_dump($request);
+        if ($request['code'] == 1) {
+            return ['code' => 1, 'msg' => '退款成功', 'data' => ['ret_sn' => $request['data']['refund_id']]];
+        } else {
+            ErrorRecord::create(['m_id' =>0, 'msg' => '微信退款失败', 'data' => json_encode($request)]);
+            return ['code' => 0, 'msg' => '微信退款失败', 'data' => ['ret_sn' => '']];
+        }
+    }
+
+    /**
+     * 微信付款到零钱
+     * @param $order_sn
+     * @param $total_fee
+     * @param $openid
+     * @param $body
+     * @return array
+     */
+    function setVerified($order_sn, $total_fee, $openid, $body)
+    {
+        $cert_file=base_path($this->cert_file);
+        $key_file=base_path($this->key_file);
+        $private_key=$this->private_key;
+        $conf = array(
+            'mch_appid' => $this->appletId,
+            'mchid' =>  $this->mch_id,
+            'openid' => $openid,
+            'partner_trade_no' => $order_sn,
+            'amount' => $total_fee * 100,
+            'check_name' => 'NO_CHECK',
+            'desc' => $body,
+
+        );
+        $order = new Unifiedorder($conf, ['cert_file' => $cert_file, 'key_file' => $key_file]);
+        $request = $order->setVerified($private_key);
+        ErrorRecord::create(['m_id' =>0, 'msg' => '微信提现记录', 'data' => json_encode($request)]);
+        return $request;
+    }
+
+
+
+}

+ 324 - 0
app/Servers/weixin/Unifiedorder.php

@@ -0,0 +1,324 @@
+<?php
+namespace App\Servers\weixin;
+
+
+use App\Servers\CommonServer;
+
+/**
+ * 统一下单
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2016/10/24
+ * Time: 11:28
+ */
+class Unifiedorder
+{
+    private $conf=array(
+        'appid'=>'',
+        'mch_id'=>'',
+        'notify_url'=>'',
+        'out_trade_no'=>'',
+        'total_fee'=>'',
+        'trade_type'=>'',
+        'body'=>''
+        //'appsecret'=>''
+
+    );
+
+    private $file_conf=[
+        'cert_file'=>'',
+        'key_file'=>''
+    ];
+    private $url='https://api.mch.weixin.qq.com/pay/unifiedorder';
+    function __construct($conf=null,$file_conf=[])
+    {
+        if($conf)$this->conf=$conf;
+        if(!empty($file_conf['cert_file'])){
+            $this->file_conf['cert_file']=$file_conf['cert_file'];
+            $this->file_conf['key_file']=empty($file_conf['key_file'])?'':$file_conf['key_file'];
+        }
+    }
+    /**
+     * 微信签名
+     */
+    public  function wxSign($data,$keys)
+    {
+        ksort($data);
+        $str='';
+        foreach($data as $key=>$val)
+        {
+            if($val)
+            {
+                if($str!='')$str.='&';
+                $str.="{$key}={$val}";
+            }
+        }
+        $str.='&key='.$keys;
+        $sign=strtoupper(MD5($str));
+        return $sign;
+    }
+    /**
+     * 获取客户端ip
+     * @return string
+     */
+    private function getIp()
+    {
+        $cip=CommonServer::creatServer()->getClientIp();
+//        if ($_SERVER['REMOTE_ADDR']) {
+//            $cip = $_SERVER['REMOTE_ADDR'];
+//        } elseif (getenv("REMOTE_ADDR")) {
+//            $cip = getenv("REMOTE_ADDR");
+//        } elseif (getenv("HTTP_CLIENT_IP")) {
+//            $cip = getenv("HTTP_CLIENT_IP");
+//        } else {
+//            $cip = "unknown";
+//        }
+        return $cip;
+    }
+    /**
+     *
+     * 产生随机字符串,不长于32位
+     * @param int $length
+     * @return 产生的随机字符串
+     */
+    public  function getNonceStr($length = 32)
+    {
+        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+        $str ="";
+        for ( $i = 0; $i < $length; $i++ )  {
+            $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
+        }
+        return $str;
+    }
+
+    /**
+     * 微信退款
+     * @param $private_key
+     * @return array
+     */
+    function wxPayRefund($private_key){
+        $data=$this->conf;
+        $data['nonce_str']=$this->getNonceStr();
+        $data['sign']=$this->wxSign($data,$private_key);
+        $xml = "<xml>";
+        foreach ($data as $key=>$val)
+        {
+            if (is_numeric($val))
+            {
+                $xml.="<".$key.">".$val."</".$key.">";
+
+            }
+            else
+                $xml.="<".$key.">".$val."</".$key.">";
+        }
+        $xml.="</xml>";
+        $url='https://api.mch.weixin.qq.com/secapi/pay/refund';
+//        $url='https://api.mch.weixin.qq.com/pay/orderquery';
+        $key_file=trim($this->file_conf['key_file'],'.');
+        $cert_file=trim($this->file_conf['cert_file'],'.');
+        if(!is_file($key_file) || !is_file($cert_file)){
+            return array('code'=>0,'data'=>'证书文件不存在');
+        }
+        $ch=curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url); //设置访问路径
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //设置可以返回字符串
+        curl_setopt($ch, CURLOPT_POST,TRUE);//post请求
+        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
+        curl_setopt($ch,CURLOPT_SSLCERT, $cert_file);
+        curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
+        curl_setopt($ch,CURLOPT_SSLKEY, $key_file);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);//设置传递的参数
+        $request=curl_exec($ch);
+        curl_close($ch);
+        $request=json_decode(json_encode(simplexml_load_string($request, 'SimpleXMLElement', LIBXML_NOCDATA)),true);
+        if($request['return_code']=='SUCCESS'&&$request['result_code']=='SUCCESS')
+        {
+            return array('code'=>1,'data'=>$request);
+        }
+        else
+        {
+            return array('code'=>0,'data'=>$request);
+        }
+    }
+
+    function getPayOrder($private_key){
+        $data=$this->conf;
+        $data['nonce_str']=$this->getNonceStr();
+//        $data['spbill_create_ip']=$this->getIp();
+        $data['sign']=$this->wxSign($data,$private_key);
+        $xml = "<xml>";
+        foreach ($data as $key=>$val)
+        {
+            if (is_numeric($val))
+            {
+                $xml.="<".$key.">".$val."</".$key.">";
+
+            }
+            else
+                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
+        }
+        $xml.="</xml>";
+        $key_file=trim($this->file_conf['key_file'],'.');
+        $cert_file=trim($this->file_conf['cert_file'],'.');
+
+        if(!is_file($key_file) || !is_file($cert_file)){
+            return array('code'=>0,'msg'=>'证书文件不存在');
+        }
+        $url='https://api.mch.weixin.qq.com/pay/orderquery';
+        $ch=curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url); //设置访问路径
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //设置可以返回字符串
+        curl_setopt($ch, CURLOPT_POST,TRUE);//post请求
+        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
+        curl_setopt($ch,CURLOPT_SSLCERT, $cert_file);
+        curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
+        curl_setopt($ch,CURLOPT_SSLKEY, $key_file);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);//设置传递的参数
+        $request=curl_exec($ch);
+        curl_close($ch);
+        $request=json_decode(json_encode(simplexml_load_string($request, 'SimpleXMLElement', LIBXML_NOCDATA)),true);
+        if($request['return_code']=='SUCCESS'&&$request['result_code']=='SUCCESS')
+        {
+
+            return array('code'=>1,'msg'=>'订单信息','data'=>$request);
+        }
+        else
+        {
+            return array('code'=>0,'msg'=>empty($request['return_msg'])?'订单信息':($request['return_msg'].','.(empty($request['err_code_des'])?'':$request['err_code_des'])),'data'=>$request);
+        }
+    }
+
+    /**
+     *获取统一支付信息
+     * @param $private_key 支付秘钥
+     * @return array
+     */
+    public function getOrder($private_key)
+    {
+        $data=$this->conf;
+        $data['nonce_str']=$this->getNonceStr();
+        $data['spbill_create_ip']=$this->getIp();
+        $data['sign']=$this->wxSign($data,$private_key);
+        $xml = "<xml>";
+        foreach ($data as $key=>$val)
+        {
+            if (is_numeric($val))
+            {
+                $xml.="<".$key.">".$val."</".$key.">";
+
+            }
+            else
+                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
+        }
+        $xml.="</xml>";
+        $ch=curl_init();
+        curl_setopt($ch, CURLOPT_URL, $this->url); //设置访问路径
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //设置可以返回字符串
+        curl_setopt($ch, CURLOPT_POST,TRUE);//post请求
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);//设置传递的参数
+        $request=curl_exec($ch);
+        curl_close($ch);
+        $request=json_decode(json_encode(simplexml_load_string($request, 'SimpleXMLElement', LIBXML_NOCDATA)),true);
+        if($request['return_code']=='SUCCESS'&&$request['result_code']=='SUCCESS')
+        {
+
+            return array('code'=>1,'data'=>$request);
+        }
+        else
+        {
+            return array('code'=>0,'data'=>$request['return_msg']);
+        }
+    }
+    /**
+     * @param $url
+     * @param string $type 请求方式
+     * @param string $postdata post数据 数组格式
+     * @return mixed
+     */
+    private  function send_request($url,$type='get',$postdata='')
+    {
+
+        $ch=curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url); //设置访问路径
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //设置可以返回字符串
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
+        $head=array('User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36');
+        curl_setopt($ch, CURLOPT_HTTPHEADER,$head);
+        if($type=='post')
+        {
+
+            curl_setopt($ch, CURLOPT_POST,TRUE);//post请求
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);//设置传递的参数
+
+        }
+        $request=curl_exec($ch);
+        curl_close($ch);
+        return $request;
+    }
+
+
+    /**
+     * 企业付款到领钱
+     * @param $private_key
+     * @return array
+     */
+    function setVerified($private_key){
+        $data=$this->conf;
+        $data['nonce_str']=$this->getNonceStr();
+//        $data['spbill_create_ip']=$this->getIp();
+        $data['spbill_create_ip']='119.23.242.246';
+        $data['sign']=$this->wxSign($data,$private_key);
+        $xml = "<xml>";
+        foreach ($data as $key=>$val)
+        {
+            if (is_numeric($val))
+            {
+                $xml.="<".$key.">".$val."</".$key.">";
+
+            }
+            else
+                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
+        }
+        $xml.="</xml>";
+        $key_file=trim($this->file_conf['key_file'],'.');
+        $cert_file=trim($this->file_conf['cert_file'],'.');
+//        dd($key_file,$cert_file);
+
+        if(!is_file($key_file) || !is_file($cert_file)){
+            return array('code'=>0,'msg'=>'证书文件不存在');
+        }
+        $url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
+        $ch=curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url); //设置访问路径
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //设置可以返回字符串
+        curl_setopt($ch, CURLOPT_POST,TRUE);//post请求
+        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
+        curl_setopt($ch,CURLOPT_SSLCERT, $cert_file);
+        curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
+        curl_setopt($ch,CURLOPT_SSLKEY, $key_file);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);//设置传递的参数
+        $request=curl_exec($ch);
+        curl_close($ch);
+        $request=json_decode(json_encode(simplexml_load_string($request, 'SimpleXMLElement', LIBXML_NOCDATA)),true);
+        if($request['return_code']=='SUCCESS'&&$request['result_code']=='SUCCESS')
+        {
+
+            return array('code'=>1,'msg'=>'提现成功','data'=>$request);
+        }
+        else
+        {
+            return array('code'=>0,'msg'=>empty($request['return_msg'])?'提现失败':($request['return_msg'].','.(empty($request['err_code_des'])?'':$request['err_code_des'])),'data'=>$request);
+        }
+    }
+
+
+}

+ 573 - 0
app/Servers/weixin/WxPay.Api.php

@@ -0,0 +1,573 @@
+<?php
+namespace App\Servers\weixin;
+
+
+/**
+ *
+ * 接口访问类,包含所有微信支付API列表的封装,类中方法为static方法,
+ * 每个接口有默认超时时间(除提交被扫支付为10s,上报超时时间为1s外,其他均为6s)
+ * @author widyhu
+ *
+ */
+class WxPayApi
+{
+	/**
+	 *
+	 * 统一下单,WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayUnifiedOrder $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function unifiedOrder($inputObj, $timeOut = 6)
+	{
+		$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
+		//检测必填参数
+		if(!$inputObj->IsOut_trade_noSet()) {
+			throw new WxPayException("缺少统一支付接口必填参数out_trade_no!");
+		}else if(!$inputObj->IsBodySet()){
+			throw new WxPayException("缺少统一支付接口必填参数body!");
+		}else if(!$inputObj->IsTotal_feeSet()) {
+			throw new WxPayException("缺少统一支付接口必填参数total_fee!");
+		}else if(!$inputObj->IsTrade_typeSet()) {
+			throw new WxPayException("缺少统一支付接口必填参数trade_type!");
+		}
+
+		//关联参数
+		if($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()){
+			throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
+		}
+		if($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()){
+			throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
+		}
+
+		//异步通知url未设置,则使用配置文件中的url
+		if(!$inputObj->IsNotify_urlSet()){
+			$inputObj->SetNotify_url($GLOBALS['notify_url']);//异步通知url
+		}
+
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
+		//$inputObj->SetSpbill_create_ip("1.1.1.1");
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		//签名
+		$inputObj->SetSign();
+		$xml = $inputObj->ToXml();
+
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, false, $timeOut);
+		$result = WxPayResults::Init($response);
+		self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
+
+		return $result;
+	}
+
+	/**
+	 *
+	 * 查询订单,WxPayOrderQuery中out_trade_no、transaction_id至少填一个
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayOrderQuery $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function orderQuery($inputObj, $timeOut = 6)
+	{
+		$url = "https://api.mch.weixin.qq.com/pay/orderquery";
+		//检测必填参数
+		if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
+			throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
+		}
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, false, $timeOut);
+		$result = WxPayResults::Init($response);
+		self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
+
+		return $result;
+	}
+
+	/**
+	 *
+	 * 关闭订单,WxPayCloseOrder中out_trade_no必填
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayCloseOrder $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function closeOrder($inputObj, $timeOut = 6)
+	{
+		$url = "https://api.mch.weixin.qq.com/pay/closeorder";
+		//检测必填参数
+		if(!$inputObj->IsOut_trade_noSet()) {
+			throw new WxPayException("订单查询接口中,out_trade_no必填!");
+		}
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, false, $timeOut);
+		$result = WxPayResults::Init($response);
+		self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
+
+		return $result;
+	}
+
+	/**
+	 *
+	 * 申请退款,WxPayRefund中out_trade_no、transaction_id至少填一个且
+	 * out_refund_no、total_fee、refund_fee、op_user_id为必填参数
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayRefund $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function refund($inputObj, $timeOut = 6)
+	{
+		$url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
+		//检测必填参数
+		if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
+			throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
+		}else if(!$inputObj->IsOut_refund_noSet()){
+			throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!");
+		}else if(!$inputObj->IsTotal_feeSet()){
+			throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
+		}else if(!$inputObj->IsRefund_feeSet()){
+			throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
+		}else if(!$inputObj->IsOp_user_idSet()){
+			throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!");
+		}
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, true, $timeOut);
+		$result = WxPayResults::Init($response);
+		self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
+
+		return $result;
+	}
+
+	/**
+	 *
+	 * 查询退款
+	 * 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,
+	 * 用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。
+	 * WxPayRefundQuery中out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayRefundQuery $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function refundQuery($inputObj, $timeOut = 6)
+	{
+		$url = "https://api.mch.weixin.qq.com/pay/refundquery";
+		//检测必填参数
+		if(!$inputObj->IsOut_refund_noSet() &&
+			!$inputObj->IsOut_trade_noSet() &&
+			!$inputObj->IsTransaction_idSet() &&
+			!$inputObj->IsRefund_idSet()) {
+			throw new WxPayException("退款查询接口中,out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个!");
+		}
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, false, $timeOut);
+		$result = WxPayResults::Init($response);
+		self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
+
+		return $result;
+	}
+
+	/**
+	 * 下载对账单,WxPayDownloadBill中bill_date为必填参数
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayDownloadBill $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function downloadBill($inputObj, $timeOut = 6)
+	{
+		$url = "https://api.mch.weixin.qq.com/pay/downloadbill";
+		//检测必填参数
+		if(!$inputObj->IsBill_dateSet()) {
+			throw new WxPayException("对账单接口中,缺少必填参数bill_date!");
+		}
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+
+		$response = self::postXmlCurl($xml, $url, false, $timeOut);
+		if(substr($response, 0 , 5) == "<xml>"){
+			return "";
+		}
+		return $response;
+	}
+
+	/**
+	 * 提交被扫支付API
+	 * 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,
+	 * 由商户收银台或者商户后台调用该接口发起支付。
+	 * WxPayWxPayMicroPay中body、out_trade_no、total_fee、auth_code参数必填
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayWxPayMicroPay $inputObj
+	 * @param int $timeOut
+	 */
+	public static function micropay($inputObj, $timeOut = 10)
+	{
+		$url = "https://api.mch.weixin.qq.com/pay/micropay";
+		//检测必填参数
+		if(!$inputObj->IsBodySet()) {
+			throw new WxPayException("提交被扫支付API接口中,缺少必填参数body!");
+		} else if(!$inputObj->IsOut_trade_noSet()) {
+			throw new WxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
+		} else if(!$inputObj->IsTotal_feeSet()) {
+			throw new WxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
+		} else if(!$inputObj->IsAuth_codeSet()) {
+			throw new WxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
+		}
+
+		$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, false, $timeOut);
+		$result = WxPayResults::Init($response);
+		self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
+
+		return $result;
+	}
+
+	/**
+	 *
+	 * 撤销订单API接口,WxPayReverse中参数out_trade_no和transaction_id必须填写一个
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayReverse $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 */
+	public static function reverse($inputObj, $timeOut = 6)
+	{
+		$url = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
+		//检测必填参数
+		if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
+			throw new WxPayException("撤销订单API接口中,参数out_trade_no和transaction_id必须填写一个!");
+		}
+
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, true, $timeOut);
+		$result = WxPayResults::Init($response);
+		self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
+
+		return $result;
+	}
+
+	/**
+	 *
+	 * 测速上报,该方法内部封装在report中,使用时请注意异常流程
+	 * WxPayReport中interface_url、return_code、result_code、user_ip、execute_time_必填
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayReport $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function report($inputObj, $timeOut = 1)
+	{
+		$url = "https://api.mch.weixin.qq.com/payitil/report";
+		//检测必填参数
+		if(!$inputObj->IsInterface_urlSet()) {
+			throw new WxPayException("接口URL,缺少必填参数interface_url!");
+		} if(!$inputObj->IsReturn_codeSet()) {
+			throw new WxPayException("返回状态码,缺少必填参数return_code!");
+		} if(!$inputObj->IsResult_codeSet()) {
+			throw new WxPayException("业务结果,缺少必填参数result_code!");
+		} if(!$inputObj->IsUser_ipSet()) {
+			throw new WxPayException("访问接口IP,缺少必填参数user_ip!");
+		} if(!$inputObj->IsExecute_time_Set()) {
+			throw new WxPayException("接口耗时,缺少必填参数execute_time_!");
+		}
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetUser_ip($_SERVER['REMOTE_ADDR']);//终端ip
+		$inputObj->SetTime(date("YmdHis"));//商户上报时间
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, false, $timeOut);
+		return $response;
+	}
+
+	/**
+	 *
+	 * 生成二维码规则,模式一生成支付二维码
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayBizPayUrl $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function bizpayurl($inputObj, $timeOut = 6)
+	{
+		if(!$inputObj->IsProduct_idSet()){
+			throw new WxPayException("生成二维码,缺少必填参数product_id!");
+		}
+
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetTime_stamp(time());//时间戳
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+
+		return $inputObj->GetValues();
+	}
+
+	/**
+	 *
+	 * 转换短链接
+	 * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
+	 * 减小二维码数据量,提升扫描速度和精确度。
+	 * appid、mchid、spbill_create_ip、nonce_str不需要填入
+	 * @param WxPayShortUrl $inputObj
+	 * @param int $timeOut
+	 * @throws WxPayException
+	 * @return 成功时返回,其他抛异常
+	 */
+	public static function shorturl($inputObj, $timeOut = 6)
+	{
+		$url = "https://api.mch.weixin.qq.com/tools/shorturl";
+		//检测必填参数
+		if(!$inputObj->IsLong_urlSet()) {
+			throw new WxPayException("需要转换的URL,签名用原串,传输需URL encode!");
+		}
+		$inputObj->SetAppid($GLOBALS['appId']);//公众账号ID
+		$inputObj->SetMch_id($GLOBALS['mchId']);//商户号
+		$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
+
+		$inputObj->SetSign();//签名
+		$xml = $inputObj->ToXml();
+
+		$startTimeStamp = self::getMillisecond();//请求开始时间
+		$response = self::postXmlCurl($xml, $url, false, $timeOut);
+		$result = WxPayResults::Init($response);
+		self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
+
+		return $result;
+	}
+
+ 	/**
+ 	 *
+ 	 * 支付结果通用通知
+ 	 * @param function $callback
+ 	 * 直接回调函数使用方法: notify(you_function);
+ 	 * 回调类成员函数方法:notify(array($this, you_function));
+ 	 * $callback  原型为:function function_name($data){}
+ 	 */
+	public static function notify($callback, &$msg)
+	{
+		//获取通知的数据
+		$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
+		//如果返回成功则验证签名
+		try {
+			$result = WxPayResults::Init($xml);
+		} catch (WxPayException $e){
+			$msg = $e->errorMessage();
+			return false;
+		}
+
+		return call_user_func($callback, $result);
+	}
+
+	/**
+	 *
+	 * 产生随机字符串,不长于32位
+	 * @param int $length
+	 * @return 产生的随机字符串
+	 */
+	public static function getNonceStr($length = 32)
+	{
+		$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+		$str ="";
+		for ( $i = 0; $i < $length; $i++ )  {
+			$str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
+		}
+		return $str;
+	}
+
+	/**
+	 * 直接输出xml
+	 * @param string $xml
+	 */
+	public static function replyNotify($xml)
+	{
+		echo $xml;
+	}
+
+	/**
+	 *
+	 * 上报数据, 上报的时候将屏蔽所有异常流程
+	 * @param string $usrl
+	 * @param int $startTimeStamp
+	 * @param array $data
+	 */
+	private static function reportCostTime($url, $startTimeStamp, $data)
+	{
+		//如果不需要上报数据
+
+		//如果仅失败上报
+		if(array_key_exists("return_code", $data) &&
+			 $data["return_code"] == "SUCCESS" &&
+			 array_key_exists("result_code", $data) &&
+			 $data["result_code"] == "SUCCESS")
+		 {
+		 	return;
+		 }
+
+		//上报逻辑
+		$endTimeStamp = self::getMillisecond();
+		$objInput = new WxPayReport();
+		$objInput->SetInterface_url($url);
+		$objInput->SetExecute_time_($endTimeStamp - $startTimeStamp);
+		//返回状态码
+		if(array_key_exists("return_code", $data)){
+			$objInput->SetReturn_code($data["return_code"]);
+		}
+		//返回信息
+		if(array_key_exists("return_msg", $data)){
+			$objInput->SetReturn_msg($data["return_msg"]);
+		}
+		//业务结果
+		if(array_key_exists("result_code", $data)){
+			$objInput->SetResult_code($data["result_code"]);
+		}
+		//错误代码
+		if(array_key_exists("err_code", $data)){
+			$objInput->SetErr_code($data["err_code"]);
+		}
+		//错误代码描述
+		if(array_key_exists("err_code_des", $data)){
+			$objInput->SetErr_code_des($data["err_code_des"]);
+		}
+		//商户订单号
+		if(array_key_exists("out_trade_no", $data)){
+			$objInput->SetOut_trade_no($data["out_trade_no"]);
+		}
+		//设备号
+		if(array_key_exists("device_info", $data)){
+			$objInput->SetDevice_info($data["device_info"]);
+		}
+
+		try{
+			self::report($objInput);
+		} catch (WxPayException $e){
+			//不做任何处理
+		}
+	}
+
+	/**
+	 * 以post方式提交xml到对应的接口url
+	 *
+	 * @param string $xml  需要post的xml数据
+	 * @param string $url  url
+	 * @param bool $useCert 是否需要证书,默认不需要
+	 * @param int $second   url执行超时时间,默认30s
+	 * @throws WxPayException
+	 */
+	private static function postXmlCurl($xml, $url, $useCert = false, $second = 30)
+	{
+		$ch = curl_init();
+		//设置超时
+		curl_setopt($ch, CURLOPT_TIMEOUT, $second);
+
+		//如果有配置代理这里就设置代理
+
+		curl_setopt($ch,CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
+		//设置header
+		curl_setopt($ch, CURLOPT_HEADER, FALSE);
+		//要求结果为字符串且输出到屏幕上
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+
+		if($useCert == true){
+			//设置证书
+			//使用证书:cert 与 key 分别属于两个.pem文件
+			curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
+			//curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
+			curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
+			//curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
+		}
+		//post提交方式
+		curl_setopt($ch, CURLOPT_POST, TRUE);
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
+		//运行curl
+		$data = curl_exec($ch);
+		//返回结果
+		if($data){
+			curl_close($ch);
+			return $data;
+		} else {
+			$error = curl_errno($ch);
+			curl_close($ch);
+			throw new WxPayException("curl出错,错误码:$error");
+		}
+	}
+
+	/**
+	 * 获取毫秒级别的时间戳
+	 */
+	private static function getMillisecond()
+	{
+		//获取毫秒的时间戳
+		$time = explode ( " ", microtime () );
+		$time = $time[1] . ($time[0] * 1000);
+		$time2 = explode( ".", $time );
+		$time = $time2[0];
+		return $time;
+	}
+}
+

+ 2984 - 0
app/Servers/weixin/WxPay.Data.php

@@ -0,0 +1,2984 @@
+<?php
+/**
+* 2015-06-29 修复签名问题
+**/
+
+namespace App\Servers\weixin;
+
+/**
+ *
+ * 数据对象基础类,该类中定义数据类最基本的行为,包括:
+ * 计算/设置/获取签名、输出xml格式的参数、从xml读取数据对象等
+ * @author widyhu
+ *
+ */
+class WxPayDataBase
+{
+	protected $values = array();
+
+	/**
+	* 设置签名,详见签名生成算法
+	* @param string $value
+	**/
+	public function SetSign()
+	{
+		$sign = $this->MakeSign();
+		$this->values['sign'] = $sign;
+		return $sign;
+	}
+
+	/**
+	* 获取签名,详见签名生成算法的值
+	* @return 值
+	**/
+	public function GetSign()
+	{
+		return $this->values['sign'];
+	}
+
+	/**
+	* 判断签名,详见签名生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsSignSet()
+	{
+		return array_key_exists('sign', $this->values);
+	}
+
+	/**
+	 * 输出xml字符
+	 * @throws WxPayException
+	**/
+	public function ToXml()
+	{
+		if(!is_array($this->values)
+			|| count($this->values) <= 0)
+		{
+    		throw new WxPayException("数组数据异常!");
+    	}
+
+    	$xml = "<xml>";
+    	foreach ($this->values as $key=>$val)
+    	{
+    		if (is_numeric($val)){
+    			$xml.="<".$key.">".$val."</".$key.">";
+    		}else{
+    			$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
+    		}
+        }
+        $xml.="</xml>";
+        return $xml;
+	}
+
+    /**
+     * 将xml转为array
+     * @param string $xml
+     * @throws WxPayException
+     */
+	public function FromXml($xml)
+	{
+		if(!$xml){
+			throw new WxPayException("xml数据异常!");
+		}
+        //将XML转为array
+        //禁止引用外部xml实体
+        libxml_disable_entity_loader(true);
+        $this->values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
+		return $this->values;
+	}
+
+	/**
+	 * 格式化参数格式化成url参数
+	 */
+	public function ToUrlParams()
+	{
+		$buff = "";
+		foreach ($this->values as $k => $v)
+		{
+			if($k != "sign" && $v != "" && !is_array($v)){
+				$buff .= $k . "=" . $v . "&";
+			}
+		}
+
+		$buff = trim($buff, "&");
+		return $buff;
+	}
+
+	/**
+	 * 生成签名
+	 * @return 签名,本函数不覆盖sign成员变量,如要设置签名需要调用SetSign方法赋值
+	 */
+	public function MakeSign()
+	{
+		//签名步骤一:按字典序排序参数
+		ksort($this->values);
+		$string = $this->ToUrlParams();
+		//签名步骤二:在string后加入KEY
+		$string = $string . "&key=".$GLOBALS['private_key'];
+		//签名步骤三:MD5加密
+		$string = md5($string);
+		//签名步骤四:所有字符转为大写
+		$result = strtoupper($string);
+		return $result;
+	}
+
+	/**
+	 * 获取设置的值
+	 */
+	public function GetValues()
+	{
+		return $this->values;
+	}
+}
+
+/**
+ *
+ * 接口调用结果类
+ * @author widyhu
+ *
+ */
+class WxPayResults extends WxPayDataBase
+{
+	/**
+	 *
+	 * 检测签名
+	 */
+	public function CheckSign()
+	{
+		//fix异常
+		if(!$this->IsSignSet()){
+			throw new WxPayException("签名错误!");
+		}
+
+		$sign = $this->MakeSign();
+		if($this->GetSign() == $sign){
+			return true;
+		}
+		throw new WxPayException("签名错误!");
+	}
+
+	/**
+	 *
+	 * 使用数组初始化
+	 * @param array $array
+	 */
+	public function FromArray($array)
+	{
+		$this->values = $array;
+	}
+
+	/**
+	 *
+	 * 使用数组初始化对象
+	 * @param array $array
+	 * @param 是否检测签名 $noCheckSign
+	 */
+	public static function InitFromArray($array, $noCheckSign = false)
+	{
+		$obj = new self();
+		$obj->FromArray($array);
+		if($noCheckSign == false){
+			$obj->CheckSign();
+		}
+        return $obj;
+	}
+
+	/**
+	 *
+	 * 设置参数
+	 * @param string $key
+	 * @param string $value
+	 */
+	public function SetData($key, $value)
+	{
+		$this->values[$key] = $value;
+	}
+
+    /**
+     * 将xml转为array
+     * @param string $xml
+     * @throws WxPayException
+     */
+	public static function Init($xml)
+	{
+		$obj = new self();
+		$obj->FromXml($xml);
+		//fix bug 2015-06-29
+		if($obj->values['return_code'] != 'SUCCESS'){
+			 return $obj->GetValues();
+		}
+		$obj->CheckSign();
+        return $obj->GetValues();
+	}
+}
+
+/**
+ *
+ * 回调基础类
+ * @author widyhu
+ *
+ */
+class WxPayNotifyReply extends  WxPayDataBase
+{
+	/**
+	 *
+	 * 设置错误码 FAIL 或者 SUCCESS
+	 * @param string
+	 */
+	public function SetReturn_code($return_code)
+	{
+		$this->values['return_code'] = $return_code;
+	}
+
+	/**
+	 *
+	 * 获取错误码 FAIL 或者 SUCCESS
+	 * @return string $return_code
+	 */
+	public function GetReturn_code()
+	{
+		return $this->values['return_code'];
+	}
+
+	/**
+	 *
+	 * 设置错误信息
+	 * @param string $return_code
+	 */
+	public function SetReturn_msg($return_msg)
+	{
+		$this->values['return_msg'] = $return_msg;
+	}
+
+	/**
+	 *
+	 * 获取错误信息
+	 * @return string
+	 */
+	public function GetReturn_msg()
+	{
+		return $this->values['return_msg'];
+	}
+
+	/**
+	 *
+	 * 设置返回参数
+	 * @param string $key
+	 * @param string $value
+	 */
+	public function SetData($key, $value)
+	{
+		$this->values[$key] = $value;
+	}
+}
+
+/**
+ *
+ * 统一下单输入对象
+ * @author widyhu
+ *
+ */
+class WxPayUnifiedOrder extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的终端设备号,商户自定义
+	* @param string $value
+	**/
+	public function SetDevice_info($value)
+	{
+		$this->values['device_info'] = $value;
+	}
+	/**
+	* 获取微信支付分配的终端设备号,商户自定义的值
+	* @return 值
+	**/
+	public function GetDevice_info()
+	{
+		return $this->values['device_info'];
+	}
+	/**
+	* 判断微信支付分配的终端设备号,商户自定义是否存在
+	* @return true 或 false
+	**/
+	public function IsDevice_infoSet()
+	{
+		return array_key_exists('device_info', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+
+	/**
+	* 设置商品或支付单简要描述
+	* @param string $value
+	**/
+	public function SetBody($value)
+	{
+		$this->values['body'] = $value;
+	}
+	/**
+	* 获取商品或支付单简要描述的值
+	* @return 值
+	**/
+	public function GetBody()
+	{
+		return $this->values['body'];
+	}
+	/**
+	* 判断商品或支付单简要描述是否存在
+	* @return true 或 false
+	**/
+	public function IsBodySet()
+	{
+		return array_key_exists('body', $this->values);
+	}
+
+
+	/**
+	* 设置商品名称明细列表
+	* @param string $value
+	**/
+	public function SetDetail($value)
+	{
+		$this->values['detail'] = $value;
+	}
+	/**
+	* 获取商品名称明细列表的值
+	* @return 值
+	**/
+	public function GetDetail()
+	{
+		return $this->values['detail'];
+	}
+	/**
+	* 判断商品名称明细列表是否存在
+	* @return true 或 false
+	**/
+	public function IsDetailSet()
+	{
+		return array_key_exists('detail', $this->values);
+	}
+
+
+	/**
+	* 设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
+	* @param string $value
+	**/
+	public function SetAttach($value)
+	{
+		$this->values['attach'] = $value;
+	}
+	/**
+	* 获取附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据的值
+	* @return 值
+	**/
+	public function GetAttach()
+	{
+		return $this->values['attach'];
+	}
+	/**
+	* 判断附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据是否存在
+	* @return true 或 false
+	**/
+	public function IsAttachSet()
+	{
+		return array_key_exists('attach', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
+	* @param string $value
+	**/
+	public function SetOut_trade_no($value)
+	{
+		$this->values['out_trade_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值
+	* @return 值
+	**/
+	public function GetOut_trade_no()
+	{
+		return $this->values['out_trade_no'];
+	}
+	/**
+	* 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_trade_noSet()
+	{
+		return array_key_exists('out_trade_no', $this->values);
+	}
+
+
+	/**
+	* 设置符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	* @param string $value
+	**/
+	public function SetFee_type($value)
+	{
+		$this->values['fee_type'] = $value;
+	}
+	/**
+	* 获取符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值
+	* @return 值
+	**/
+	public function GetFee_type()
+	{
+		return $this->values['fee_type'];
+	}
+	/**
+	* 判断符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在
+	* @return true 或 false
+	**/
+	public function IsFee_typeSet()
+	{
+		return array_key_exists('fee_type', $this->values);
+	}
+
+
+	/**
+	* 设置订单总金额,只能为整数,详见支付金额
+	* @param string $value
+	**/
+	public function SetTotal_fee($value)
+	{
+		$this->values['total_fee'] = $value;
+	}
+	/**
+	* 获取订单总金额,只能为整数,详见支付金额的值
+	* @return 值
+	**/
+	public function GetTotal_fee()
+	{
+		return $this->values['total_fee'];
+	}
+	/**
+	* 判断订单总金额,只能为整数,详见支付金额是否存在
+	* @return true 或 false
+	**/
+	public function IsTotal_feeSet()
+	{
+		return array_key_exists('total_fee', $this->values);
+	}
+
+
+	/**
+	* 设置APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
+	* @param string $value
+	**/
+	public function SetSpbill_create_ip($value)
+	{
+		$this->values['spbill_create_ip'] = $value;
+	}
+	/**
+	* 获取APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。的值
+	* @return 值
+	**/
+	public function GetSpbill_create_ip()
+	{
+		return $this->values['spbill_create_ip'];
+	}
+	/**
+	* 判断APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。是否存在
+	* @return true 或 false
+	**/
+	public function IsSpbill_create_ipSet()
+	{
+		return array_key_exists('spbill_create_ip', $this->values);
+	}
+
+
+	/**
+	* 设置订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
+	* @param string $value
+	**/
+	public function SetTime_start($value)
+	{
+		$this->values['time_start'] = $value;
+	}
+	/**
+	* 获取订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则的值
+	* @return 值
+	**/
+	public function GetTime_start()
+	{
+		return $this->values['time_start'];
+	}
+	/**
+	* 判断订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则是否存在
+	* @return true 或 false
+	**/
+	public function IsTime_startSet()
+	{
+		return array_key_exists('time_start', $this->values);
+	}
+
+
+	/**
+	* 设置订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
+	* @param string $value
+	**/
+	public function SetTime_expire($value)
+	{
+		$this->values['time_expire'] = $value;
+	}
+	/**
+	* 获取订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则的值
+	* @return 值
+	**/
+	public function GetTime_expire()
+	{
+		return $this->values['time_expire'];
+	}
+	/**
+	* 判断订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则是否存在
+	* @return true 或 false
+	**/
+	public function IsTime_expireSet()
+	{
+		return array_key_exists('time_expire', $this->values);
+	}
+
+
+	/**
+	* 设置商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
+	* @param string $value
+	**/
+	public function SetGoods_tag($value)
+	{
+		$this->values['goods_tag'] = $value;
+	}
+	/**
+	* 获取商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠的值
+	* @return 值
+	**/
+	public function GetGoods_tag()
+	{
+		return $this->values['goods_tag'];
+	}
+	/**
+	* 判断商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠是否存在
+	* @return true 或 false
+	**/
+	public function IsGoods_tagSet()
+	{
+		return array_key_exists('goods_tag', $this->values);
+	}
+
+
+	/**
+	* 设置接收微信支付异步通知回调地址
+	* @param string $value
+	**/
+	public function SetNotify_url($value)
+	{
+		$this->values['notify_url'] = $value;
+	}
+	/**
+	* 获取接收微信支付异步通知回调地址的值
+	* @return 值
+	**/
+	public function GetNotify_url()
+	{
+		return $this->values['notify_url'];
+	}
+	/**
+	* 判断接收微信支付异步通知回调地址是否存在
+	* @return true 或 false
+	**/
+	public function IsNotify_urlSet()
+	{
+		return array_key_exists('notify_url', $this->values);
+	}
+
+
+	/**
+	* 设置取值如下:JSAPI,NATIVE,APP,详细说明见参数规定
+	* @param string $value
+	**/
+	public function SetTrade_type($value)
+	{
+		$this->values['trade_type'] = $value;
+	}
+	/**
+	* 获取取值如下:JSAPI,NATIVE,APP,详细说明见参数规定的值
+	* @return 值
+	**/
+	public function GetTrade_type()
+	{
+		return $this->values['trade_type'];
+	}
+	/**
+	* 判断取值如下:JSAPI,NATIVE,APP,详细说明见参数规定是否存在
+	* @return true 或 false
+	**/
+	public function IsTrade_typeSet()
+	{
+		return array_key_exists('trade_type', $this->values);
+	}
+
+
+	/**
+	* 设置trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
+	* @param string $value
+	**/
+	public function SetProduct_id($value)
+	{
+		$this->values['product_id'] = $value;
+	}
+	/**
+	* 获取trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。的值
+	* @return 值
+	**/
+	public function GetProduct_id()
+	{
+		return $this->values['product_id'];
+	}
+	/**
+	* 判断trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。是否存在
+	* @return true 或 false
+	**/
+	public function IsProduct_idSet()
+	{
+		return array_key_exists('product_id', $this->values);
+	}
+
+
+	/**
+	* 设置trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。
+	* @param string $value
+	**/
+	public function SetOpenid($value)
+	{
+		$this->values['openid'] = $value;
+	}
+	/**
+	* 获取trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。 的值
+	* @return 值
+	**/
+	public function GetOpenid()
+	{
+		return $this->values['openid'];
+	}
+	/**
+	* 判断trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。 是否存在
+	* @return true 或 false
+	**/
+	public function IsOpenidSet()
+	{
+		return array_key_exists('openid', $this->values);
+	}
+}
+
+/**
+ *
+ * 订单查询输入对象
+ * @author widyhu
+ *
+ */
+class WxPayOrderQuery extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置微信的订单号,优先使用
+	* @param string $value
+	**/
+	public function SetTransaction_id($value)
+	{
+		$this->values['transaction_id'] = $value;
+	}
+	/**
+	* 获取微信的订单号,优先使用的值
+	* @return 值
+	**/
+	public function GetTransaction_id()
+	{
+		return $this->values['transaction_id'];
+	}
+	/**
+	* 判断微信的订单号,优先使用是否存在
+	* @return true 或 false
+	**/
+	public function IsTransaction_idSet()
+	{
+		return array_key_exists('transaction_id', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号,当没提供transaction_id时需要传这个。
+	* @param string $value
+	**/
+	public function SetOut_trade_no($value)
+	{
+		$this->values['out_trade_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号,当没提供transaction_id时需要传这个。的值
+	* @return 值
+	**/
+	public function GetOut_trade_no()
+	{
+		return $this->values['out_trade_no'];
+	}
+	/**
+	* 判断商户系统内部的订单号,当没提供transaction_id时需要传这个。是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_trade_noSet()
+	{
+		return array_key_exists('out_trade_no', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+}
+
+/**
+ *
+ * 关闭订单输入对象
+ * @author widyhu
+ *
+ */
+class WxPayCloseOrder extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号
+	* @param string $value
+	**/
+	public function SetOut_trade_no($value)
+	{
+		$this->values['out_trade_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号的值
+	* @return 值
+	**/
+	public function GetOut_trade_no()
+	{
+		return $this->values['out_trade_no'];
+	}
+	/**
+	* 判断商户系统内部的订单号是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_trade_noSet()
+	{
+		return array_key_exists('out_trade_no', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+}
+
+/**
+ *
+ * 提交退款输入对象
+ * @author widyhu
+ *
+ */
+class WxPayRefund extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的终端设备号,与下单一致
+	* @param string $value
+	**/
+	public function SetDevice_info($value)
+	{
+		$this->values['device_info'] = $value;
+	}
+	/**
+	* 获取微信支付分配的终端设备号,与下单一致的值
+	* @return 值
+	**/
+	public function GetDevice_info()
+	{
+		return $this->values['device_info'];
+	}
+	/**
+	* 判断微信支付分配的终端设备号,与下单一致是否存在
+	* @return true 或 false
+	**/
+	public function IsDevice_infoSet()
+	{
+		return array_key_exists('device_info', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+
+	/**
+	* 设置微信订单号
+	* @param string $value
+	**/
+	public function SetTransaction_id($value)
+	{
+		$this->values['transaction_id'] = $value;
+	}
+	/**
+	* 获取微信订单号的值
+	* @return 值
+	**/
+	public function GetTransaction_id()
+	{
+		return $this->values['transaction_id'];
+	}
+	/**
+	* 判断微信订单号是否存在
+	* @return true 或 false
+	**/
+	public function IsTransaction_idSet()
+	{
+		return array_key_exists('transaction_id', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no
+	* @param string $value
+	**/
+	public function SetOut_trade_no($value)
+	{
+		$this->values['out_trade_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no的值
+	* @return 值
+	**/
+	public function GetOut_trade_no()
+	{
+		return $this->values['out_trade_no'];
+	}
+	/**
+	* 判断商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_trade_noSet()
+	{
+		return array_key_exists('out_trade_no', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
+	* @param string $value
+	**/
+	public function SetOut_refund_no($value)
+	{
+		$this->values['out_refund_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔的值
+	* @return 值
+	**/
+	public function GetOut_refund_no()
+	{
+		return $this->values['out_refund_no'];
+	}
+	/**
+	* 判断商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_refund_noSet()
+	{
+		return array_key_exists('out_refund_no', $this->values);
+	}
+
+
+	/**
+	* 设置订单总金额,单位为分,只能为整数,详见支付金额
+	* @param string $value
+	**/
+	public function SetTotal_fee($value)
+	{
+		$this->values['total_fee'] = $value;
+	}
+	/**
+	* 获取订单总金额,单位为分,只能为整数,详见支付金额的值
+	* @return 值
+	**/
+	public function GetTotal_fee()
+	{
+		return $this->values['total_fee'];
+	}
+	/**
+	* 判断订单总金额,单位为分,只能为整数,详见支付金额是否存在
+	* @return true 或 false
+	**/
+	public function IsTotal_feeSet()
+	{
+		return array_key_exists('total_fee', $this->values);
+	}
+
+
+	/**
+	* 设置退款总金额,订单总金额,单位为分,只能为整数,详见支付金额
+	* @param string $value
+	**/
+	public function SetRefund_fee($value)
+	{
+		$this->values['refund_fee'] = $value;
+	}
+	/**
+	* 获取退款总金额,订单总金额,单位为分,只能为整数,详见支付金额的值
+	* @return 值
+	**/
+	public function GetRefund_fee()
+	{
+		return $this->values['refund_fee'];
+	}
+	/**
+	* 判断退款总金额,订单总金额,单位为分,只能为整数,详见支付金额是否存在
+	* @return true 或 false
+	**/
+	public function IsRefund_feeSet()
+	{
+		return array_key_exists('refund_fee', $this->values);
+	}
+
+
+	/**
+	* 设置货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	* @param string $value
+	**/
+	public function SetRefund_fee_type($value)
+	{
+		$this->values['refund_fee_type'] = $value;
+	}
+	/**
+	* 获取货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值
+	* @return 值
+	**/
+	public function GetRefund_fee_type()
+	{
+		return $this->values['refund_fee_type'];
+	}
+	/**
+	* 判断货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在
+	* @return true 或 false
+	**/
+	public function IsRefund_fee_typeSet()
+	{
+		return array_key_exists('refund_fee_type', $this->values);
+	}
+
+
+	/**
+	* 设置操作员帐号, 默认为商户号
+	* @param string $value
+	**/
+	public function SetOp_user_id($value)
+	{
+		$this->values['op_user_id'] = $value;
+	}
+	/**
+	* 获取操作员帐号, 默认为商户号的值
+	* @return 值
+	**/
+	public function GetOp_user_id()
+	{
+		return $this->values['op_user_id'];
+	}
+	/**
+	* 判断操作员帐号, 默认为商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsOp_user_idSet()
+	{
+		return array_key_exists('op_user_id', $this->values);
+	}
+}
+
+/**
+ *
+ * 退款查询输入对象
+ * @author widyhu
+ *
+ */
+class WxPayRefundQuery extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的终端设备号
+	* @param string $value
+	**/
+	public function SetDevice_info($value)
+	{
+		$this->values['device_info'] = $value;
+	}
+	/**
+	* 获取微信支付分配的终端设备号的值
+	* @return 值
+	**/
+	public function GetDevice_info()
+	{
+		return $this->values['device_info'];
+	}
+	/**
+	* 判断微信支付分配的终端设备号是否存在
+	* @return true 或 false
+	**/
+	public function IsDevice_infoSet()
+	{
+		return array_key_exists('device_info', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+
+	/**
+	* 设置微信订单号
+	* @param string $value
+	**/
+	public function SetTransaction_id($value)
+	{
+		$this->values['transaction_id'] = $value;
+	}
+	/**
+	* 获取微信订单号的值
+	* @return 值
+	**/
+	public function GetTransaction_id()
+	{
+		return $this->values['transaction_id'];
+	}
+	/**
+	* 判断微信订单号是否存在
+	* @return true 或 false
+	**/
+	public function IsTransaction_idSet()
+	{
+		return array_key_exists('transaction_id', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号
+	* @param string $value
+	**/
+	public function SetOut_trade_no($value)
+	{
+		$this->values['out_trade_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号的值
+	* @return 值
+	**/
+	public function GetOut_trade_no()
+	{
+		return $this->values['out_trade_no'];
+	}
+	/**
+	* 判断商户系统内部的订单号是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_trade_noSet()
+	{
+		return array_key_exists('out_trade_no', $this->values);
+	}
+
+
+	/**
+	* 设置商户退款单号
+	* @param string $value
+	**/
+	public function SetOut_refund_no($value)
+	{
+		$this->values['out_refund_no'] = $value;
+	}
+	/**
+	* 获取商户退款单号的值
+	* @return 值
+	**/
+	public function GetOut_refund_no()
+	{
+		return $this->values['out_refund_no'];
+	}
+	/**
+	* 判断商户退款单号是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_refund_noSet()
+	{
+		return array_key_exists('out_refund_no', $this->values);
+	}
+
+
+	/**
+	* 设置微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no
+	* @param string $value
+	**/
+	public function SetRefund_id($value)
+	{
+		$this->values['refund_id'] = $value;
+	}
+	/**
+	* 获取微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no的值
+	* @return 值
+	**/
+	public function GetRefund_id()
+	{
+		return $this->values['refund_id'];
+	}
+	/**
+	* 判断微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no是否存在
+	* @return true 或 false
+	**/
+	public function IsRefund_idSet()
+	{
+		return array_key_exists('refund_id', $this->values);
+	}
+}
+
+/**
+ *
+ * 下载对账单输入对象
+ * @author widyhu
+ *
+ */
+class WxPayDownloadBill extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单
+	* @param string $value
+	**/
+	public function SetDevice_info($value)
+	{
+		$this->values['device_info'] = $value;
+	}
+	/**
+	* 获取微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单的值
+	* @return 值
+	**/
+	public function GetDevice_info()
+	{
+		return $this->values['device_info'];
+	}
+	/**
+	* 判断微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单是否存在
+	* @return true 或 false
+	**/
+	public function IsDevice_infoSet()
+	{
+		return array_key_exists('device_info', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+
+	/**
+	* 设置下载对账单的日期,格式:20140603
+	* @param string $value
+	**/
+	public function SetBill_date($value)
+	{
+		$this->values['bill_date'] = $value;
+	}
+	/**
+	* 获取下载对账单的日期,格式:20140603的值
+	* @return 值
+	**/
+	public function GetBill_date()
+	{
+		return $this->values['bill_date'];
+	}
+	/**
+	* 判断下载对账单的日期,格式:20140603是否存在
+	* @return true 或 false
+	**/
+	public function IsBill_dateSet()
+	{
+		return array_key_exists('bill_date', $this->values);
+	}
+
+
+	/**
+	* 设置ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单
+	* @param string $value
+	**/
+	public function SetBill_type($value)
+	{
+		$this->values['bill_type'] = $value;
+	}
+	/**
+	* 获取ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单的值
+	* @return 值
+	**/
+	public function GetBill_type()
+	{
+		return $this->values['bill_type'];
+	}
+	/**
+	* 判断ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单是否存在
+	* @return true 或 false
+	**/
+	public function IsBill_typeSet()
+	{
+		return array_key_exists('bill_type', $this->values);
+	}
+}
+
+/**
+ *
+ * 测速上报输入对象
+ * @author widyhu
+ *
+ */
+class WxPayReport extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的终端设备号,商户自定义
+	* @param string $value
+	**/
+	public function SetDevice_info($value)
+	{
+		$this->values['device_info'] = $value;
+	}
+	/**
+	* 获取微信支付分配的终端设备号,商户自定义的值
+	* @return 值
+	**/
+	public function GetDevice_info()
+	{
+		return $this->values['device_info'];
+	}
+	/**
+	* 判断微信支付分配的终端设备号,商户自定义是否存在
+	* @return true 或 false
+	**/
+	public function IsDevice_infoSet()
+	{
+		return array_key_exists('device_info', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+
+
+	/**
+	* 设置上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。
+	* @param string $value
+	**/
+	public function SetInterface_url($value)
+	{
+		$this->values['interface_url'] = $value;
+	}
+	/**
+	* 获取上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。的值
+	* @return 值
+	**/
+	public function GetInterface_url()
+	{
+		return $this->values['interface_url'];
+	}
+	/**
+	* 判断上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。是否存在
+	* @return true 或 false
+	**/
+	public function IsInterface_urlSet()
+	{
+		return array_key_exists('interface_url', $this->values);
+	}
+
+
+	/**
+	* 设置接口耗时情况,单位为毫秒
+	* @param string $value
+	**/
+	public function SetExecute_time_($value)
+	{
+		$this->values['execute_time_'] = $value;
+	}
+	/**
+	* 获取接口耗时情况,单位为毫秒的值
+	* @return 值
+	**/
+	public function GetExecute_time_()
+	{
+		return $this->values['execute_time_'];
+	}
+	/**
+	* 判断接口耗时情况,单位为毫秒是否存在
+	* @return true 或 false
+	**/
+	public function IsExecute_time_Set()
+	{
+		return array_key_exists('execute_time_', $this->values);
+	}
+
+
+	/**
+	* 设置SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断
+	* @param string $value
+	**/
+	public function SetReturn_code($value)
+	{
+		$this->values['return_code'] = $value;
+	}
+	/**
+	* 获取SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断的值
+	* @return 值
+	**/
+	public function GetReturn_code()
+	{
+		return $this->values['return_code'];
+	}
+	/**
+	* 判断SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断是否存在
+	* @return true 或 false
+	**/
+	public function IsReturn_codeSet()
+	{
+		return array_key_exists('return_code', $this->values);
+	}
+
+
+	/**
+	* 设置返回信息,如非空,为错误原因签名失败参数格式校验错误
+	* @param string $value
+	**/
+	public function SetReturn_msg($value)
+	{
+		$this->values['return_msg'] = $value;
+	}
+	/**
+	* 获取返回信息,如非空,为错误原因签名失败参数格式校验错误的值
+	* @return 值
+	**/
+	public function GetReturn_msg()
+	{
+		return $this->values['return_msg'];
+	}
+	/**
+	* 判断返回信息,如非空,为错误原因签名失败参数格式校验错误是否存在
+	* @return true 或 false
+	**/
+	public function IsReturn_msgSet()
+	{
+		return array_key_exists('return_msg', $this->values);
+	}
+
+
+	/**
+	* 设置SUCCESS/FAIL
+	* @param string $value
+	**/
+	public function SetResult_code($value)
+	{
+		$this->values['result_code'] = $value;
+	}
+	/**
+	* 获取SUCCESS/FAIL的值
+	* @return 值
+	**/
+	public function GetResult_code()
+	{
+		return $this->values['result_code'];
+	}
+	/**
+	* 判断SUCCESS/FAIL是否存在
+	* @return true 或 false
+	**/
+	public function IsResult_codeSet()
+	{
+		return array_key_exists('result_code', $this->values);
+	}
+
+
+	/**
+	* 设置ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误
+	* @param string $value
+	**/
+	public function SetErr_code($value)
+	{
+		$this->values['err_code'] = $value;
+	}
+	/**
+	* 获取ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误的值
+	* @return 值
+	**/
+	public function GetErr_code()
+	{
+		return $this->values['err_code'];
+	}
+	/**
+	* 判断ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误是否存在
+	* @return true 或 false
+	**/
+	public function IsErr_codeSet()
+	{
+		return array_key_exists('err_code', $this->values);
+	}
+
+
+	/**
+	* 设置结果信息描述
+	* @param string $value
+	**/
+	public function SetErr_code_des($value)
+	{
+		$this->values['err_code_des'] = $value;
+	}
+	/**
+	* 获取结果信息描述的值
+	* @return 值
+	**/
+	public function GetErr_code_des()
+	{
+		return $this->values['err_code_des'];
+	}
+	/**
+	* 判断结果信息描述是否存在
+	* @return true 或 false
+	**/
+	public function IsErr_code_desSet()
+	{
+		return array_key_exists('err_code_des', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。
+	* @param string $value
+	**/
+	public function SetOut_trade_no($value)
+	{
+		$this->values['out_trade_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 的值
+	* @return 值
+	**/
+	public function GetOut_trade_no()
+	{
+		return $this->values['out_trade_no'];
+	}
+	/**
+	* 判断商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_trade_noSet()
+	{
+		return array_key_exists('out_trade_no', $this->values);
+	}
+
+
+	/**
+	* 设置发起接口调用时的机器IP
+	* @param string $value
+	**/
+	public function SetUser_ip($value)
+	{
+		$this->values['user_ip'] = $value;
+	}
+	/**
+	* 获取发起接口调用时的机器IP 的值
+	* @return 值
+	**/
+	public function GetUser_ip()
+	{
+		return $this->values['user_ip'];
+	}
+	/**
+	* 判断发起接口调用时的机器IP 是否存在
+	* @return true 或 false
+	**/
+	public function IsUser_ipSet()
+	{
+		return array_key_exists('user_ip', $this->values);
+	}
+
+
+	/**
+	* 设置系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
+	* @param string $value
+	**/
+	public function SetTime($value)
+	{
+		$this->values['time'] = $value;
+	}
+	/**
+	* 获取系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则的值
+	* @return 值
+	**/
+	public function GetTime()
+	{
+		return $this->values['time'];
+	}
+	/**
+	* 判断系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则是否存在
+	* @return true 或 false
+	**/
+	public function IsTimeSet()
+	{
+		return array_key_exists('time', $this->values);
+	}
+}
+
+/**
+ *
+ * 短链转换输入对象
+ * @author widyhu
+ *
+ */
+class WxPayShortUrl extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置需要转换的URL,签名用原串,传输需URL encode
+	* @param string $value
+	**/
+	public function SetLong_url($value)
+	{
+		$this->values['long_url'] = $value;
+	}
+	/**
+	* 获取需要转换的URL,签名用原串,传输需URL encode的值
+	* @return 值
+	**/
+	public function GetLong_url()
+	{
+		return $this->values['long_url'];
+	}
+	/**
+	* 判断需要转换的URL,签名用原串,传输需URL encode是否存在
+	* @return true 或 false
+	**/
+	public function IsLong_urlSet()
+	{
+		return array_key_exists('long_url', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+}
+
+/**
+ *
+ * 提交被扫输入对象
+ * @author widyhu
+ *
+ */
+class WxPayMicroPay extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置终端设备号(商户自定义,如门店编号)
+	* @param string $value
+	**/
+	public function SetDevice_info($value)
+	{
+		$this->values['device_info'] = $value;
+	}
+	/**
+	* 获取终端设备号(商户自定义,如门店编号)的值
+	* @return 值
+	**/
+	public function GetDevice_info()
+	{
+		return $this->values['device_info'];
+	}
+	/**
+	* 判断终端设备号(商户自定义,如门店编号)是否存在
+	* @return true 或 false
+	**/
+	public function IsDevice_infoSet()
+	{
+		return array_key_exists('device_info', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+
+	/**
+	* 设置商品或支付单简要描述
+	* @param string $value
+	**/
+	public function SetBody($value)
+	{
+		$this->values['body'] = $value;
+	}
+	/**
+	* 获取商品或支付单简要描述的值
+	* @return 值
+	**/
+	public function GetBody()
+	{
+		return $this->values['body'];
+	}
+	/**
+	* 判断商品或支付单简要描述是否存在
+	* @return true 或 false
+	**/
+	public function IsBodySet()
+	{
+		return array_key_exists('body', $this->values);
+	}
+
+
+	/**
+	* 设置商品名称明细列表
+	* @param string $value
+	**/
+	public function SetDetail($value)
+	{
+		$this->values['detail'] = $value;
+	}
+	/**
+	* 获取商品名称明细列表的值
+	* @return 值
+	**/
+	public function GetDetail()
+	{
+		return $this->values['detail'];
+	}
+	/**
+	* 判断商品名称明细列表是否存在
+	* @return true 或 false
+	**/
+	public function IsDetailSet()
+	{
+		return array_key_exists('detail', $this->values);
+	}
+
+
+	/**
+	* 设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
+	* @param string $value
+	**/
+	public function SetAttach($value)
+	{
+		$this->values['attach'] = $value;
+	}
+	/**
+	* 获取附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据的值
+	* @return 值
+	**/
+	public function GetAttach()
+	{
+		return $this->values['attach'];
+	}
+	/**
+	* 判断附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据是否存在
+	* @return true 或 false
+	**/
+	public function IsAttachSet()
+	{
+		return array_key_exists('attach', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
+	* @param string $value
+	**/
+	public function SetOut_trade_no($value)
+	{
+		$this->values['out_trade_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值
+	* @return 值
+	**/
+	public function GetOut_trade_no()
+	{
+		return $this->values['out_trade_no'];
+	}
+	/**
+	* 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_trade_noSet()
+	{
+		return array_key_exists('out_trade_no', $this->values);
+	}
+
+
+	/**
+	* 设置订单总金额,单位为分,只能为整数,详见支付金额
+	* @param string $value
+	**/
+	public function SetTotal_fee($value)
+	{
+		$this->values['total_fee'] = $value;
+	}
+	/**
+	* 获取订单总金额,单位为分,只能为整数,详见支付金额的值
+	* @return 值
+	**/
+	public function GetTotal_fee()
+	{
+		return $this->values['total_fee'];
+	}
+	/**
+	* 判断订单总金额,单位为分,只能为整数,详见支付金额是否存在
+	* @return true 或 false
+	**/
+	public function IsTotal_feeSet()
+	{
+		return array_key_exists('total_fee', $this->values);
+	}
+
+
+	/**
+	* 设置符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+	* @param string $value
+	**/
+	public function SetFee_type($value)
+	{
+		$this->values['fee_type'] = $value;
+	}
+	/**
+	* 获取符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值
+	* @return 值
+	**/
+	public function GetFee_type()
+	{
+		return $this->values['fee_type'];
+	}
+	/**
+	* 判断符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在
+	* @return true 或 false
+	**/
+	public function IsFee_typeSet()
+	{
+		return array_key_exists('fee_type', $this->values);
+	}
+
+
+	/**
+	* 设置调用微信支付API的机器IP
+	* @param string $value
+	**/
+	public function SetSpbill_create_ip($value)
+	{
+		$this->values['spbill_create_ip'] = $value;
+	}
+	/**
+	* 获取调用微信支付API的机器IP 的值
+	* @return 值
+	**/
+	public function GetSpbill_create_ip()
+	{
+		return $this->values['spbill_create_ip'];
+	}
+	/**
+	* 判断调用微信支付API的机器IP 是否存在
+	* @return true 或 false
+	**/
+	public function IsSpbill_create_ipSet()
+	{
+		return array_key_exists('spbill_create_ip', $this->values);
+	}
+
+
+	/**
+	* 设置订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则
+	* @param string $value
+	**/
+	public function SetTime_start($value)
+	{
+		$this->values['time_start'] = $value;
+	}
+	/**
+	* 获取订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则的值
+	* @return 值
+	**/
+	public function GetTime_start()
+	{
+		return $this->values['time_start'];
+	}
+	/**
+	* 判断订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则是否存在
+	* @return true 或 false
+	**/
+	public function IsTime_startSet()
+	{
+		return array_key_exists('time_start', $this->values);
+	}
+
+
+	/**
+	* 设置订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则
+	* @param string $value
+	**/
+	public function SetTime_expire($value)
+	{
+		$this->values['time_expire'] = $value;
+	}
+	/**
+	* 获取订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则的值
+	* @return 值
+	**/
+	public function GetTime_expire()
+	{
+		return $this->values['time_expire'];
+	}
+	/**
+	* 判断订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则是否存在
+	* @return true 或 false
+	**/
+	public function IsTime_expireSet()
+	{
+		return array_key_exists('time_expire', $this->values);
+	}
+
+
+	/**
+	* 设置商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
+	* @param string $value
+	**/
+	public function SetGoods_tag($value)
+	{
+		$this->values['goods_tag'] = $value;
+	}
+	/**
+	* 获取商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠的值
+	* @return 值
+	**/
+	public function GetGoods_tag()
+	{
+		return $this->values['goods_tag'];
+	}
+	/**
+	* 判断商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠是否存在
+	* @return true 或 false
+	**/
+	public function IsGoods_tagSet()
+	{
+		return array_key_exists('goods_tag', $this->values);
+	}
+
+
+	/**
+	* 设置扫码支付授权码,设备读取用户微信中的条码或者二维码信息
+	* @param string $value
+	**/
+	public function SetAuth_code($value)
+	{
+		$this->values['auth_code'] = $value;
+	}
+	/**
+	* 获取扫码支付授权码,设备读取用户微信中的条码或者二维码信息的值
+	* @return 值
+	**/
+	public function GetAuth_code()
+	{
+		return $this->values['auth_code'];
+	}
+	/**
+	* 判断扫码支付授权码,设备读取用户微信中的条码或者二维码信息是否存在
+	* @return true 或 false
+	**/
+	public function IsAuth_codeSet()
+	{
+		return array_key_exists('auth_code', $this->values);
+	}
+}
+
+/**
+ *
+ * 撤销输入对象
+ * @author widyhu
+ *
+ */
+class WxPayReverse extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+
+	/**
+	* 设置微信的订单号,优先使用
+	* @param string $value
+	**/
+	public function SetTransaction_id($value)
+	{
+		$this->values['transaction_id'] = $value;
+	}
+	/**
+	* 获取微信的订单号,优先使用的值
+	* @return 值
+	**/
+	public function GetTransaction_id()
+	{
+		return $this->values['transaction_id'];
+	}
+	/**
+	* 判断微信的订单号,优先使用是否存在
+	* @return true 或 false
+	**/
+	public function IsTransaction_idSet()
+	{
+		return array_key_exists('transaction_id', $this->values);
+	}
+
+
+	/**
+	* 设置商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no
+	* @param string $value
+	**/
+	public function SetOut_trade_no($value)
+	{
+		$this->values['out_trade_no'] = $value;
+	}
+	/**
+	* 获取商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no的值
+	* @return 值
+	**/
+	public function GetOut_trade_no()
+	{
+		return $this->values['out_trade_no'];
+	}
+	/**
+	* 判断商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no是否存在
+	* @return true 或 false
+	**/
+	public function IsOut_trade_noSet()
+	{
+		return array_key_exists('out_trade_no', $this->values);
+	}
+
+
+	/**
+	* 设置随机字符串,不长于32位。推荐随机数生成算法
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串,不长于32位。推荐随机数生成算法的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+}
+
+/**
+ *
+ * 提交JSAPI输入对象
+ * @author widyhu
+ *
+ */
+class WxPayJsApiPay extends WxPayDataBase
+{
+	/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appId'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appId'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appId', $this->values);
+	}
+
+
+	/**
+	* 设置支付时间戳
+	* @param string $value
+	**/
+	public function SetTimeStamp($value)
+	{
+		$this->values['timeStamp'] = $value;
+	}
+	/**
+	* 获取支付时间戳的值
+	* @return 值
+	**/
+	public function GetTimeStamp()
+	{
+		return $this->values['timeStamp'];
+	}
+	/**
+	* 判断支付时间戳是否存在
+	* @return true 或 false
+	**/
+	public function IsTimeStampSet()
+	{
+		return array_key_exists('timeStamp', $this->values);
+	}
+
+	/**
+	* 随机字符串
+	* @param string $value
+	**/
+	public function SetNonceStr($value)
+	{
+		$this->values['nonceStr'] = $value;
+	}
+	/**
+	* 获取notify随机字符串值
+	* @return 值
+	**/
+	public function GetReturn_code()
+	{
+		return $this->values['nonceStr'];
+	}
+	/**
+	* 判断随机字符串是否存在
+	* @return true 或 false
+	**/
+	public function IsReturn_codeSet()
+	{
+		return array_key_exists('nonceStr', $this->values);
+	}
+
+
+	/**
+	* 设置订单详情扩展字符串
+	* @param string $value
+	**/
+	public function SetPackage($value)
+	{
+		$this->values['package'] = $value;
+	}
+	/**
+	* 获取订单详情扩展字符串的值
+	* @return 值
+	**/
+	public function GetPackage()
+	{
+		return $this->values['package'];
+	}
+	/**
+	* 判断订单详情扩展字符串是否存在
+	* @return true 或 false
+	**/
+	public function IsPackageSet()
+	{
+		return array_key_exists('package', $this->values);
+	}
+
+	/**
+	* 设置签名方式
+	* @param string $value
+	**/
+	public function SetSignType($value)
+	{
+		$this->values['signType'] = $value;
+	}
+	/**
+	* 获取签名方式
+	* @return 值
+	**/
+	public function GetSignType()
+	{
+		return $this->values['signType'];
+	}
+	/**
+	* 判断签名方式是否存在
+	* @return true 或 false
+	**/
+	public function IsSignTypeSet()
+	{
+		return array_key_exists('signType', $this->values);
+	}
+
+	/**
+	* 设置签名方式
+	* @param string $value
+	**/
+	public function SetPaySign($value)
+	{
+		$this->values['paySign'] = $value;
+	}
+	/**
+	* 获取签名方式
+	* @return 值
+	**/
+	public function GetPaySign()
+	{
+		return $this->values['paySign'];
+	}
+	/**
+	* 判断签名方式是否存在
+	* @return true 或 false
+	**/
+	public function IsPaySignSet()
+	{
+		return array_key_exists('paySign', $this->values);
+	}
+}
+
+/**
+ *
+ * 扫码支付模式一生成二维码参数
+ * @author widyhu
+ *
+ */
+class WxPayBizPayUrl extends WxPayDataBase
+{
+		/**
+	* 设置微信分配的公众账号ID
+	* @param string $value
+	**/
+	public function SetAppid($value)
+	{
+		$this->values['appid'] = $value;
+	}
+	/**
+	* 获取微信分配的公众账号ID的值
+	* @return 值
+	**/
+	public function GetAppid()
+	{
+		return $this->values['appid'];
+	}
+	/**
+	* 判断微信分配的公众账号ID是否存在
+	* @return true 或 false
+	**/
+	public function IsAppidSet()
+	{
+		return array_key_exists('appid', $this->values);
+	}
+
+
+	/**
+	* 设置微信支付分配的商户号
+	* @param string $value
+	**/
+	public function SetMch_id($value)
+	{
+		$this->values['mch_id'] = $value;
+	}
+	/**
+	* 获取微信支付分配的商户号的值
+	* @return 值
+	**/
+	public function GetMch_id()
+	{
+		return $this->values['mch_id'];
+	}
+	/**
+	* 判断微信支付分配的商户号是否存在
+	* @return true 或 false
+	**/
+	public function IsMch_idSet()
+	{
+		return array_key_exists('mch_id', $this->values);
+	}
+
+	/**
+	* 设置支付时间戳
+	* @param string $value
+	**/
+	public function SetTime_stamp($value)
+	{
+		$this->values['time_stamp'] = $value;
+	}
+	/**
+	* 获取支付时间戳的值
+	* @return 值
+	**/
+	public function GetTime_stamp()
+	{
+		return $this->values['time_stamp'];
+	}
+	/**
+	* 判断支付时间戳是否存在
+	* @return true 或 false
+	**/
+	public function IsTime_stampSet()
+	{
+		return array_key_exists('time_stamp', $this->values);
+	}
+
+	/**
+	* 设置随机字符串
+	* @param string $value
+	**/
+	public function SetNonce_str($value)
+	{
+		$this->values['nonce_str'] = $value;
+	}
+	/**
+	* 获取随机字符串的值
+	* @return 值
+	**/
+	public function GetNonce_str()
+	{
+		return $this->values['nonce_str'];
+	}
+	/**
+	* 判断随机字符串是否存在
+	* @return true 或 false
+	**/
+	public function IsNonce_strSet()
+	{
+		return array_key_exists('nonce_str', $this->values);
+	}
+
+	/**
+	* 设置商品ID
+	* @param string $value
+	**/
+	public function SetProduct_id($value)
+	{
+		$this->values['product_id'] = $value;
+	}
+	/**
+	* 获取商品ID的值
+	* @return 值
+	**/
+	public function GetProduct_id()
+	{
+		return $this->values['product_id'];
+	}
+	/**
+	* 判断商品ID是否存在
+	* @return true 或 false
+	**/
+	public function IsProduct_idSet()
+	{
+		return array_key_exists('product_id', $this->values);
+	}
+}

+ 15 - 0
app/Servers/weixin/WxPay.Exception.php

@@ -0,0 +1,15 @@
+<?php
+namespace App\Servers\weixin;
+use Exception;
+/**
+ *
+ * 微信支付API异常类
+ * @author widyhu
+ *
+ */
+class WxPayException extends Exception {
+	public function errorMessage()
+	{
+		return $this->getMessage();
+	}
+}

+ 140 - 0
app/Servers/weixin/WxPay.MicroPay.php

@@ -0,0 +1,140 @@
+<?php
+namespace App\Servers\weixin;
+/**
+ *
+ * 刷卡支付实现类
+ * 该类实现了一个刷卡支付的流程,流程如下:
+ * 1、提交刷卡支付
+ * 2、根据返回结果决定是否需要查询订单,如果查询之后订单还未变则需要返回查询(一般反复查10次)
+ * 3、如果反复查询10订单依然不变,则发起撤销订单
+ * 4、撤销订单需要循环撤销,一直撤销成功为止(注意循环次数,建议10次)
+ *
+ * 该类是微信支付提供的样例程序,商户可根据自己的需求修改,或者使用lib中的api自行开发,为了防止
+ * 查询时hold住后台php进程,商户查询和撤销逻辑可在前端调用
+ *
+ * @author widy
+ *
+ */
+class MicroPay
+{
+	/**
+	 *
+	 * 提交刷卡支付,并且确认结果,接口比较慢
+	 * @param WxPayMicroPay $microPayInput
+	 * @throws WxpayException
+	 * @return 返回查询接口的结果
+	 */
+	public function pay($microPayInput)
+	{
+		//①、提交被扫支付
+		$result = WxPayApi::micropay($microPayInput, 5);
+
+
+		//签名验证
+		$out_trade_no = $microPayInput->GetOut_trade_no();
+
+		//②、接口调用成功,明确返回调用失败
+		if($result["return_code"] == "SUCCESS" &&
+		   $result["result_code"] == "FAIL" &&
+		   $result["err_code"] != "USERPAYING" &&
+		   $result["err_code"] != "SYSTEMERROR")
+		{
+			return false;
+		}
+
+		//③、确认支付是否成功
+		$queryTimes = 10;
+		while($queryTimes > 0)
+		{
+			$succResult = 0;
+			$queryResult = $this->query($out_trade_no, $succResult);
+			//如果需要等待1s后继续
+			if($succResult == 2){
+				sleep(2);
+				continue;
+			} else if($succResult == 1){//查询成功
+				return $queryResult;
+			} else {//订单交易失败
+				return false;
+			}
+		}
+
+		//④、次确认失败,则撤销订单
+		if(!$this->cancel($out_trade_no))
+		{
+			throw new WxpayException("撤销单失败!");
+		}
+
+		return false;
+	}
+
+	/**
+	 *
+	 * 查询订单情况
+	 * @param string $out_trade_no  商户订单号
+	 * @param int $succCode         查询订单结果
+	 * @return 0 订单不成功,1表示订单成功,2表示继续等待
+	 */
+	public function query($out_trade_no, &$succCode)
+	{
+		$queryOrderInput = new WxPayOrderQuery();
+		$queryOrderInput->SetOut_trade_no($out_trade_no);
+		$result = WxPayApi::orderQuery($queryOrderInput);
+
+		if($result["return_code"] == "SUCCESS"
+			&& $result["result_code"] == "SUCCESS")
+		{
+			//支付成功
+			if($result["trade_state"] == "SUCCESS"){
+				$succCode = 1;
+			   	return $result;
+			}
+			//用户支付中
+			else if($result["trade_state"] == "USERPAYING"){
+				$succCode = 2;
+				return false;
+			}
+		}
+
+		//如果返回错误码为“此交易订单号不存在”则直接认定失败
+		if($result["err_code"] == "ORDERNOTEXIST")
+		{
+			$succCode = 0;
+		} else{
+			//如果是系统错误,则后续继续
+			$succCode = 2;
+		}
+		return false;
+	}
+
+	/**
+	 *
+	 * 撤销订单,如果失败会重复调用10次
+	 * @param string $out_trade_no
+	 * @param 调用深度 $depth
+	 */
+	public function cancel($out_trade_no, $depth = 0)
+	{
+		if($depth > 10){
+			return false;
+		}
+
+		$clostOrder = new WxPayReverse();
+		$clostOrder->SetOut_trade_no($out_trade_no);
+		$result = WxPayApi::reverse($clostOrder);
+
+		//接口调用失败
+		if($result["return_code"] != "SUCCESS"){
+			return false;
+		}
+
+		//如果结果为success且不需要重新调用撤销,则表示撤销成功
+		if($result["result_code"] != "SUCCESS"
+			&& $result["recall"] == "N"){
+			return true;
+		} else if($result["recall"] == "Y") {
+			return $this->cancel($out_trade_no, ++$depth);
+		}
+		return false;
+	}
+}

+ 10 - 0
routes/api/notify.php

@@ -0,0 +1,10 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+
+
+Route::group(['domain' => env('APP_HOST_API'), 'prefix' => 'notify'],function (){
+    Route::match(['get','post'],'order_wx', 'NotifyController@orderWx')->name('notify.order_wx');//订单微信支付回调
+
+});

+ 15 - 0
routes/api/order.php

@@ -0,0 +1,15 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+
+
+Route::group(['domain' => env('APP_HOST_API'), 'prefix' => 'order'],function (){
+    Route::match(['get','post'],'status', 'OrderController@getOrderStatus')->name('order.status');//订单状态
+    Route::match(['get','post'],'create', 'OrderController@createOrder')->name('order.create');//订单创建
+    Route::match(['get','post'],'pay', 'OrderController@payOrder')->name('order.pay');//订单支付
+    Route::match(['get','post'],'list', 'OrderController@getOrderList')->name('order.list');//订单列表
+    Route::match(['get','post'],'cancel', 'OrderController@cancelOrder')->name('order.cancel');//取消订单
+    Route::match(['get','post'],'info', 'OrderController@getOrderInfo')->name('order.info');//订单详情
+
+});