fly %!s(int64=5) %!d(string=hai) anos
pai
achega
7eac87a118

+ 1 - 1
app/Http/Controllers/QuickApp/BaseController.php

@@ -13,7 +13,7 @@ class BaseController extends Controller
     {
         if (!isset($this->field[$name])) {
             $qapp_user = QappUserService::getGolableUserStatic();
-            if ($name == '_user_info') {
+            if ($name == 'user_info') {
                 $this->field[$name] = $qapp_user->user;
             }
             if ($name == 'uid') {

+ 16 - 23
app/Http/Controllers/QuickApp/Order/OrdersController.php

@@ -361,7 +361,7 @@ class OrdersController extends BaseController
     {
         $product_id = $request->get('product_id', 0);
         $send_order_id = $request->get('send_order_id', 0);
-        if (empty($product_id) || empty($sign)) {
+        if (!$product_id) {
             return response()->error('QAPP_PARAM_ERROR');
         }
         $bid = $request->get('bid', 0);
@@ -386,7 +386,7 @@ class OrdersController extends BaseController
             $order_type = '';
         }
 
-        $res = $this->createUnPayOrder([
+        $this->createUnPayOrder([
             'distribution_channel_id' => $distribution_channel_id,
             'uid' => $uid,
             'product_id' => $product_id,
@@ -404,29 +404,23 @@ class OrdersController extends BaseController
         ]);
         $config = [
             // 微信支付参数
-            'app_id'     => 'wxf065f7364b078a73', // 应用ID
-            'mch_id'     => '1500977641', // 微信支付商户号
-            'mch_key'    => '0e7SfPt3EOS0HC1GxVa4fqmCUINcN71E', // 微信支付密钥
+            'appid'     => 'wxf065f7364b078a73', // 应用ID
+            'merchant_id'     => '1500977641', // 微信支付商户号
+            'key'    => '0e7SfPt3EOS0HC1GxVa4fqmCUINcN71E', // 微信支付密钥
+            'trade_type' => 'APP',
         ];
         $pay = WechatPay::Official('OFFICIALPAY', $config);
         try {
             $payOrder = [
-                'out_trade_no'     => $trade_no, // 订单号
-                'total_fee'        => $price, // 订单金额,**单位:分**
-                'body'             => '阅读云阅 小说', // 订单描述
-                'spbill_create_ip' => _getIp(), // 支付人的 IP
-                'notify_url'       => env('WECHART_APP_PAY_CALL_BACK_URL'), // 定义通知URL
-                'attach'            => 'QuickApp'
+                'trade_no'     => $trade_no, // 订单号
+                'price'        => $price, // 订单金额,**单位:分**
+                'body'             => '快应用 小说', // 订单描述
+                'create_ip' => _getIp(), // 支付人的 IP
+                'remark'            => 'QuickApp'
             ];
             $result = $pay->send($payOrder);
-            if ($result && isset($result['prepayid'])) {
-                $data['appid'] = $result['appid'];
-                $data['partnerid'] = $result['partnerid'];
-                $data['prepayid'] = $result['prepayid'];
-                $data['timestamp'] = $result['timestamp'];
-                $data['noncestr'] = $result['noncestr'];
-                $data['packagInfo'] = $result['package'];
-                $data['sign'] = $result['sign'];
+            if ($result) {
+                return response()->success($result);
             } else {
                 Log::error("创建微信订单失败," . json_encode($result));
                 return response()->error('APP_CREATE_WECHAT_ORDER_FAIL');
@@ -491,12 +485,11 @@ class OrdersController extends BaseController
      */
     function wxback_xcx(Request $request)
     {
-        Log::info('-------------en----------------');
         $options = [
-            'app_id' => 'wxa0c8331eba3b34d5',
+            'app_id' => 'wxf065f7364b078a73',
             'payment' => [
-                'merchant_id' => 1501944981,
-                'key' => 'ee245088b93ba88008279d95f6d30413',
+                'merchant_id' => 1500977641,
+                'key' => '0e7SfPt3EOS0HC1GxVa4fqmCUINcN71E',
             ]
         ];
         $app = new Application($options);

+ 15 - 21
app/Http/Controllers/QuickApp/User/UserController.php

@@ -10,6 +10,7 @@ use App\Modules\User\Services\UserService;
 use Log;
 use Redis;
 use Cookie;
+
 class UserController extends BaseController
 {
     /**
@@ -58,35 +59,28 @@ class UserController extends BaseController
      *         }
      *     }
      */
-    public function index(){
-        $data = UserService::getById($this->uid);
-        if(!$data->head_img){
+    public function index()
+    {
+        $data =  $this->user_info;
+        if (!$data->head_img) {
             $data->head_img = 'https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/defaulthead.png';
         }
         $data['is_vip'] = 0;
         $data['vip_days'] = 0;
         $year_record = YearOrderService::getRecord($this->uid);
-        if($year_record){
+        if ($year_record) {
             $data['is_vip'] = 1;
-            
-            $time = strtotime($year_record['end_time'])-time();
-            if($time>=86400){
-                  $data['vip_days'] = floor($time/86400).'天';  
-            }elseif ($time>3600) {
-                 $data['vip_days'] = floor($time/3600).'小时';  
-            }elseif ($time>60) {
-                 $data['vip_days'] = floor($time/60).'分钟';  
-            }else{
-                $data['vip_days'] = $time.'秒';  
+            $time = strtotime($year_record['end_time']) - time();
+            if ($time >= 86400) {
+                $data['vip_days'] = floor($time / 86400) . '天';
+            } elseif ($time > 3600) {
+                $data['vip_days'] = floor($time / 3600) . '小时';
+            } elseif ($time > 60) {
+                $data['vip_days'] = floor($time / 60) . '分钟';
+            } else {
+                $data['vip_days'] = $time . '秒';
             }
         }
         return response()->success($data);
     }
-
-    function logout()
-    {
-        setcookie(env('COOKIE_AUTH_WEB_WECHAT'), '', -1);
-        setcookie('u', '', -1);
-        return response('logout');
-    }
 }

+ 2 - 6
app/Http/Routes/QuickApp/QuickAppRoutes.php

@@ -3,10 +3,8 @@
 Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Controllers\QuickApp'], function () {
     //登录
     Route::post('login', 'Oauth\UsersController@index');
-    //支付
-    Route::any('pay/wcback_xchengxu', 'Order\OrdersController@wxindex');
+    //刷新token
     Route::get('refreshToken', 'Oauth\UsersController@refreshToken');
-
     //支付回调
     Route::any('pay/wcback', 'Order\OrdersController@wxback_xcx');
 
@@ -32,7 +30,7 @@ Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Contr
 
         //目录分页
         Route::get('books/{bid}/catalog', 'Book\ChapterController@getCatalogPerPage');
-        
+
         //章节详情
         Route::get('books/{bid}/chapters/{cid}', 'Book\ChapterController@index')->where('cid', '\d+');
         //余额订购
@@ -49,8 +47,6 @@ Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Contr
 
         Route::get('order/issuccess', 'Order\OrdersController@isSuccess');
         Route::get('userinfo', 'User\UserController@index');
-
-
         //书架
         Route::get('userShelfBooks', 'User\UserShelfBooksController@index');
         //添加书架

+ 45 - 29
app/Libs/Pay/Merchants/Official.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Created by PhpStorm.
  * User: z-yang
@@ -22,26 +23,28 @@ class Official
     private $key;
     private $cert_path;
     private $key_path;
+    private $trade_type;
+
     public $app;
     public function __construct($config)
     {
         $this->appid = $config['appid'];
-        $this->secret = $config['secret'];
-        $this->token = $config['token'];
         $this->merchant_id = $config['merchant_id'];
         $this->key = $config['key'];
-        $this->cert_path = $config['cert_path'];
-        $this->key_path = $config['key_path'];
-
+        $this->secret = isset($config['secret']) ? $config['secret'] : '';
+        $this->token = isset($config['token']) ? $config['token'] : '';
+        $this->key_path = isset($config['key_path']) ? $config['key_path'] : '';
+        $this->cert_path = isset($config['cert_path']) ? $config['cert_path'] : '';
+        $this->trade_type = isset($config['trade_type']) ? $config['trade_type'] : 'JSAPI';
         $options = [
-            'app_id'=>$this->appid,
-            'secret'=>$this->secret,
-            'token'=>$this->token,
-            'payment'=>[
-                'merchant_id'=>$this->merchant_id,
-                'key'=>$this->key,
-                'cert_path'=>public_path($this->cert_path),
-                'key_path'=>public_path($this->key_path)
+            'app_id' => $this->appid,
+            'secret' => $this->secret,
+            'token' => $this->token,
+            'payment' => [
+                'merchant_id' => $this->merchant_id,
+                'key' => $this->key,
+                'cert_path' => public_path($this->cert_path),
+                'key_path' => public_path($this->key_path)
             ]
         ];
         $this->app = new Application($options);
@@ -49,36 +52,49 @@ class Official
 
     function send($data)
     {
-        Log::info('Official---enter--------------');
         $app =  $this->app;
         $payment = $app->payment;
         $attributes = [
-            'trade_type' => 'JSAPI',
+            'trade_type' => $this->trade_type,
             'body' => $data['body'],
-            'detail' => $data['detail'],
+            'detail' => isset($data['detail']) ? $data['detail'] : '',
             'out_trade_no' => $data['trade_no'],
             'total_fee' => $data['price'],
             'notify_url' => env('OFFICIAL_PAY_CALL_BACK_URL'),
-            'openid' => $data['openid'],
+            'openid' => isset($data['openid']) ? $data['openid'] : '',
             'spbill_create_ip' => $data['create_ip'],
             'attach' => $data['remark']
         ];
         $order = new Wxorder($attributes);
         $result = $payment->prepare($order);
-        Log::info('Official -------pay-----result---------- order is: '.$data['trade_no']);
+        Log::info('Official -------pay-----result---------- order is: ' . $data['trade_no']);
         Log::info($result);
         if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
-            $data = [
-                'appId' => $result->appid,
-                'package' => 'prepay_id=' . $result->prepay_id,
-                'nonceStr' => $result->nonce_str,
-                'timeStamp' => time(),
-                'signType' => 'MD5',
-            ];
-            $data['paySign'] = $this->MakeSign($data);
+            switch ($this->trade_type) {
+                case 'JSAPI':
+                    $data = [
+                        'appId' => $result->appid,
+                        'package' => 'prepay_id=' . $result->prepay_id,
+                        'nonceStr' => $result->nonce_str,
+                        'timeStamp' => time(),
+                        'signType' => 'MD5',
+                    ];
+                    $data['paySign'] = $this->MakeSign($data);
+                    break;
+                case 'APP':
+                    $data = [
+                        'appId' => $result->appid,
+                        'mch_id' => $result->mch_id,
+                        'prepay_id' => $result->prepay_id,
+                        'nonce_str' => $result->nonce_str,
+                        'sign' => $result->sign,
+                        'trade_type' => $result->trade_type,
+                    ];
+                    break;
+            }
             return $data;
         }
-        Log::error('pay error order is: '.$data['trade_no']);
+        Log::error('pay error order is: ' . $data['trade_no']);
         Log::error($result);
         return [];
     }
@@ -96,11 +112,11 @@ class Official
         }
         $buff = trim($buff, "&");
         //签名步骤二:在string后加入KEY
-        $string = $buff . "&key=".$this->key;
+        $string = $buff . "&key=" . $this->key;
         //签名步骤三:MD5加密
         $string = md5($string);
         //签名步骤四:所有字符转为大写
         $result = strtoupper($string);
         return $result;
     }
-}
+}