فهرست منبع

Merge branch 'stabble' of iqiyoo:zhuishuyun_wap into dist-debug

zz 6 سال پیش
والد
کامیت
3e27f8c06e

+ 61 - 0
app/Console/Commands/BookTest.php

@@ -2,9 +2,13 @@
 
 namespace App\Console\Commands;
 
+use App\Jobs\SendTexts;
 use App\Modules\Book\Services\BookSubscribleChapterService;
+use App\Modules\Product\Services\ProductService;
 use App\Modules\Subscribe\Services\ChapterOrderService;
+use App\Modules\Subscribe\Services\SubstituteOrderService;
 use App\Modules\User\Services\ReadRecordService;
+use App\Modules\User\Services\UserService;
 use App\Modules\YunQi\Models\BookUser;
 use App\Modules\YunQi\Models\YqUserBidRelation;
 use App\Modules\YunQi\Models\YqZsyTest;
@@ -69,6 +73,7 @@ class BookTest extends Command
         //$this->sendOrderStats105();
         //$this->you2();
         //$this->transfromUserOrder();
+        $this->successPayPushMsg();
     }
 
 
@@ -557,4 +562,60 @@ class BookTest extends Command
         }
     }
 
+
+    protected function successPayPushMsg()
+    {
+        try {
+            $uid = 10008;
+            $order_id = 10910163;
+            $product_info = ProductService::getProductSingle(2);
+            $force_sub_info = DB::table('force_subscribe_users')->where('uid',$uid)->where('is_subscribed', 1)->get();
+            $data = UserService::getById($uid);
+            if (!in_array($data->distribution_channel_id, [5, 123])) {
+                //return false;
+            }
+            if ($force_sub_info) {
+                //$content_format = "您好,你已经成功充值\r\n\r\n会员:%s\r\n会员ID:%s\r\n充值金额:%s\r\n充值状态:充值成功\r\n如有疑问,请点击用户中心-联系客服\r\n\r\n><a href='%s'>点击继续阅读上次阅读</a>";
+                if (SubstituteOrderService::getByOrderId($order_id)) {
+                    $content_format = "代充值客服消息:\r\n\r\n你好,您的好友为你代付成功\r\n会员:%s\r\n会员ID:%s\r\n代付金额:%s\r\n充值状态:充值成功\r\n如有疑问,请点击用户中心-联系客服\r\n\r\n><a href='%s'>点击继续阅读上次阅读</a>";
+                } else {
+                    $content_format = "您好,你已经成功充值\r\n\r\n会员:%s\r\n会员ID:%s\r\n充值金额:%s\r\n充值状态:充值成功\r\n如有疑问,请点击用户中心-联系客服\r\n\r\n><a href='%s'>点击继续阅读上次阅读</a>";
+                }
+                if ($product_info->type == 'YEAR_ORDER') {
+                    $money_text = $product_info->price . '元(尊贵的年费VIP会员)';
+                } elseif ($product_info->type == 'TICKET_RECHARGE') {
+                    if ($product_info->given) {
+                        $money_text = $product_info->price . '元(' . ($product_info->price * 100) . '书币+赠送' . $product_info->given . '书币)';
+                    } else {
+                        $money_text = $product_info->price . '元(' . ($product_info->price * 100) . '书币)';
+                    }
+                } else {
+                    $money_text = '未知';
+                }
+                $delay = 0;
+                $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($data->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/continue';;
+                $content = sprintf($content_format, $data->nickname ? $data->nickname : '匿名', $uid, $money_text, $url);
+                foreach ($force_sub_info as $item){
+                    $res['openid'] = $item->openid;
+                    $res['appid'] = $item->appid;
+                    $res['content'] = $content;
+                    $res['type'] = 'one_task';
+                    $res['send_time'] = date("Y-m-d H:i:s");
+                    $res['task_id'] = md5('pay_success_push');
+                    $send_data = array(
+                        'send_time' => date("Y-m-d H:i:s"),
+                        'data' => $res
+                    );
+                    Log::info($send_data);
+                    dispatch((new SendTexts($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_texts_list'));
+                }
+
+            }
+        } catch (\Exception $e) {
+            Log::info('pay_success_push error');
+            Log::info($e);
+        }
+        return true;
+    }
+
 }

+ 1 - 1
app/Http/Controllers/Wap/Order/OrdersController.php

@@ -637,7 +637,7 @@ class OrdersController extends BaseController
         if(!$start_time){
             return 0;
         }
-        if(!in_array($this->distribution_channel_id,[14,123,211,5,8,160,4236,4237,4241])){
+        if(!in_array($this->distribution_channel_id,[14,123,211,5,8,160,4236,4237,4241,374,243,244,245,320,321,324,337,338,538,539,751,752,753,754,4331,4384,4578,4580,4768,4769,4778,130,163,164,165,166,4126])){
             return 0;
         }
 

+ 221 - 22
app/Http/Controllers/Wap/Pay/OrdersController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Wap\Pay;
 
+use App\Modules\Book\Services\ChapterService;
 use App\Modules\Subscribe\Services\SubstituteOrderService;
 use App\Modules\User\Services\ReadRecordService;
 use Illuminate\Routing\Controller;
@@ -24,7 +25,7 @@ use EasyWeChat\Support\XML;
 use App\Modules\OfficialAccount\Services\ForceSubscribeService;
 use App\Jobs\SendTexts;
 use App\Jobs\SendStatisticsList;
-use App\Libs\SMS;
+use App\Libs\AliSMS;
 use App\Modules\Activity\Services\ActivityService;
 use App\Modules\SendOrder\Services\SendOrderService;
 use GuzzleHttp\Client;
@@ -131,8 +132,11 @@ class OrdersController extends Controller
             return response()->error('WAP_PARAM_ERROR');
         }
         //获取支付类型
-        $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $channel->pay_merchant_id)->where('is_enabled', 1)->first();
+        $pay_merchant = DB::table('pay_merchants')->select('id','appid', 'source', 'config_info')->where('id', $channel->pay_merchant_id)->where('is_enabled', 1)->first();
         if (!$pay_merchant || !$pay_merchant->appid || !$pay_merchant->source) return response()->error('WAP_PARAM_ERROR');
+        if($pay_merchant->source == 'PALMPAYV2'){
+            return redirect()->to($this->paympay($request,$pay_merchant));
+        }
         //重定向 获取用户信息的次数
         $n++;
         if ($n >= 5) {
@@ -353,6 +357,187 @@ class OrdersController extends Controller
         return view('pay.order.index', compact('pay_info', 'referer', 'jsSdkSign', 'pay_order'));
     }
 
+
+    private function paympay(Request $request,$pay_merchant){
+        $product_id =  $request->get('product_id');
+        $uid = $request->get('uid');
+        $distribution_channel_id = $request->get('distribution_channel_id');
+        $pay_redirect_url = $request->get('pay_redirect_url');
+        $send_order_id = $request->get('send_order_id',0) ;
+        $activity_id = $request->get('activity_id',0) ;
+        $suid= $request->get('suid',0);
+        $bid = $request->has('bid') ? $request->get('bid') : 0;
+        $hash_bid = $bid;
+        $fromtype = $request->has('fromtype') ? $request->get('fromtype') : $request->get('from','main');
+
+        //根据分校id获取支付配置id
+        Log::info($request->all());
+
+        $trade_no =$trade_no = date("YmdHis") . hexdec(uniqid());;
+        $order_info = OrderService::getByTradeNo($trade_no);
+        if ($order_info) return response()->error('WAP_SYS_ERROR');
+
+        $cid = $request->has('cid') ? $request->get('cid') : '';
+        $product_info = ProductService::getProductSingle($product_id,false);
+        //新用户只能冲一次
+        //Log::info('新用户只能冲一次:' .$product_info->type);
+        if($this->isNewUserSecondCharge($product_info->type,$product_id,$uid)){
+            $url = env('PROTOCOL', 'https') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST', 'leyuee') . '.com/pay';
+            return redirect()->to($url);
+        }
+        $price = $product_info->price * 100;
+        if ($uid < 32) {
+            $price = 1;
+        }
+        if (!$send_order_id) {
+            try {
+                $send_order_id = (int)Redis::hget('book_read:' . $uid, 'send_order_id');
+            } catch (\Exception $e) {}
+        }
+        $this->updateUserSendOrderId($uid,$send_order_id);
+        if (in_array($uid, explode(',', env('TEST_UID')))) {
+            $price = 1;
+        }
+
+        try {
+            $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
+            Redis::hset($key, $uid, time());
+            $date = date('Y-m-d');
+            Redis::hincrby('order_stat:' . $distribution_channel_id, 'order_num_' . $date, 1);
+            if ($send_order_id) {
+                Redis::hincrby('order_promotion_stat:' . $send_order_id, 'order_num_' . $date, 1);
+                Redis::hincrby('order_promotion_stat:' . $send_order_id, 'total', 1);
+            }
+        } catch (\Exception  $e) {
+
+        }
+
+        $data = [];
+
+        $data['price'] = $price;
+        $data['create_ip'] = $request->getClientIp();
+        $data['body'] = 'novel read';
+        $official_name = $this->getSubscribeOfficialName($uid);
+        if ($official_name) {
+            $data['body'] = '搜索公众号' . $official_name . ',请继续阅读';
+        }
+        $data['detail'] = 'novel read';
+        $data['trade_no'] = $trade_no;
+
+        if ($product_info->type == 'YEAR_ORDER') {
+            $order_type = 'YEAR';
+        } elseif ($product_info->type == 'BOOK_ORDER') {
+            $order_type = 'BOOK';
+        } elseif ($product_info->type == 'TICKET_RECHARGE') {
+            $order_type = 'RECHARGE';
+        } elseif($product_info->type == 'NEW_USER'){
+            $order_type = 'RECHARGE';
+        }else{
+            $order_type = 'UNKNOWN';
+        }
+
+        $send_order_name = '';
+        if ($send_order_id) {
+            $send_order_info = SendOrderService::getById($send_order_id);
+            if ($send_order_info && isset($send_order_info->name) && !empty($send_order_info->name)) {
+                $send_order_name = $send_order_info->name;
+            }
+        }
+        if($suid){
+            $user_info = UserService::getById($uid);
+            $distribution_channel_id = $user_info->distribution_channel_id;
+        }
+        $from_bid = ReadRecordService::getSimpleFirstReadRecord($uid);
+        $inner_send_order_id = ReadRecordService::getInnerSendOrderId($uid);
+        $init_order = [
+            'distribution_channel_id' => $distribution_channel_id,
+            'uid' => $uid,
+            'product_id' => $product_id,
+            'price' => $price / 100,
+            'pay_type' => 1,
+            'trade_no' => $data['trade_no'],
+            'pay_merchant_source' => 'PALMPAY',
+            'pay_merchant_id' => $pay_merchant->id,
+            'create_ip' => $request->getClientIp(),
+            'send_order_id' => $send_order_id,
+            'send_order_name' => $send_order_name,
+            'order_type' => $order_type,
+            'from_bid' => $from_bid,
+            'from_type' => $fromtype,
+            'activity_id' => $activity_id,
+            'inner_send_order_id'=>$inner_send_order_id
+        ];
+        $result = $this->createUnPayOrder($init_order);
+
+        //订单创建成功后增加统计
+        if($result)
+        {
+            $this->orderCreated($init_order);
+        }
+        if ($suid) {
+            $this->createSubstituteOrder($result->id, $uid, $suid);
+        }
+
+        if ($suid) {
+            $prize_fee = (int)(($product_info->price*100)*0.1);
+            //$help_pay_page_channel_id = env('HELP_PAY_PAGE_CHANNEL_ID', 123);
+            $help_pay_page_channel_id = $distribution_channel_id;
+            $url_format = '%s://site%s.%s.com/helppay?back=%s&su=%s';
+            $pay_redirect_url = sprintf(
+                $url_format,
+                env('PROTOCOL'),
+                encodeDistributionChannelId($help_pay_page_channel_id),
+                env('CUSTOM_HOST'),
+                $prize_fee,
+                $uid
+            );
+        }
+        $de_pay_redirect_url = urldecode($pay_redirect_url);
+        /*if ($request->has('cid')) {
+            $de_pay_redirect_url = $de_pay_redirect_url . '&cid=' . $request->get('cid');
+        }*/
+
+        $pay_url_info = parse_url($de_pay_redirect_url);
+        $data['pay_wait_url'] = $pay_url_info['scheme'] . '://' . $pay_url_info['host'] . '/pay/waitv2?order=' . $data['trade_no'] . '&redirect=' . urlencode($de_pay_redirect_url);
+        Log::info($data);
+
+        $config = [];
+        if ($pay_merchant->config_info) {
+            $config = json_decode($pay_merchant->config_info, true);
+        }
+        $wechatPay = WechatPay::instance($pay_merchant->source, $config);
+        \Log::info('$wechatPay is');
+        //\Log::info($wechatPay);
+        if (!$wechatPay) return response()->error('WAP_PARAM_ERROR');
+        \Log::info('$wechatPay ok-------------------');
+        $pay_info = $wechatPay->send($data);
+        \Log::info('send ok-------------------');
+        return $pay_info;
+    }
+
+    public function waitPageV2(Request $request)
+    {
+        $order = $request->get('order');
+        $order = (string)$order;
+        $url = urldecode($request->get('redirect'));
+        if(substr_count($url,'?') >1){
+            $url = str_replace_last('?','&',$url);
+        }
+        $url_info = parse_url($url);
+        if (isset($url_info['query']) && !empty($url_info['query'])) {
+            parse_str($url_info['query'], $path);
+            if (isset($path['success']) && $path['success'] == 0) {
+                if (isset($url_info['path']) && str_contains($url_info['path'], 'reader') && isset($path['cid']) && !empty($path['cid'])) {
+                    $chapter_info = ChapterService::getChapterNameByIdNoCheck($path['cid']);
+                    $path['cid'] = $chapter_info->prev_cid;
+                    $url = sprintf('%s://%s/reader?%s', $url_info['scheme'], $url_info['host'], http_build_query($path));
+                }
+                return redirect($url);
+            }
+        }
+        return view('pay.order.wait', compact('order', 'url'));
+    }
+
     private  function isNewUserSecondCharge($charge_type,$product_id,$uid){
         //Log::info('新用户只能冲一次:' .$charge_type);
         if($charge_type == 'NEW_USER'){
@@ -1160,7 +1345,7 @@ class OrdersController extends Controller
     protected function successPayPushMsg($uid, $product_info, $order_id)
     {
         try {
-            $force_sub_info = $this->getSubscribe($uid);
+            $force_sub_info = $this->getSubscribeV2($uid);
             $data = UserService::getById($uid);
             if (!in_array($data->distribution_channel_id, [5, 123])) {
                 //return false;
@@ -1186,22 +1371,25 @@ class OrdersController extends Controller
                 $delay = 0;
                 $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($data->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/continue';;
                 $content = sprintf($content_format, $data->nickname ? $data->nickname : '匿名', $uid, $money_text, $url);
-                $res['openid'] = $force_sub_info->openid;
-                $res['appid'] = $force_sub_info->appid;
-                $res['content'] = $content;
-                $res['type'] = 'one_task';
-                $res['send_time'] = date("Y-m-d H:i:s");
-                $res['task_id'] = md5('pay_success_push');
-                $send_data = array(
-                    'send_time' => date("Y-m-d H:i:s"),
-                    'data' => $res
-                );
-                dispatch((new SendTexts($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_texts_list'));
+                foreach ($force_sub_info as $item){
+                    $res['openid'] = $item->openid;
+                    $res['appid'] = $item->appid;
+                    $res['content'] = $content;
+                    $res['type'] = 'one_task';
+                    $res['send_time'] = date("Y-m-d H:i:s");
+                    $res['task_id'] = md5('pay_success_push');
+                    $send_data = array(
+                        'send_time' => date("Y-m-d H:i:s"),
+                        'data' => $res
+                    );
+
+                    dispatch((new SendTexts($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_texts_list'));
+                }
             }
         } catch (\Exception $e) {
-
+            Log::info('pay_success_push error');
+            Log::info($e);
         }
-
         return true;
     }
 
@@ -1248,6 +1436,11 @@ class OrdersController extends Controller
         return ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $uid]);
     }
 
+    private function getSubscribeV2($uid)
+    {
+        return DB::table('force_subscribe_users')->where('uid',$uid)->where('is_subscribed', 1)->get();
+    }
+
     public function getSubscribeOfficialName($uid)
     {
         $subscribe = $this->getSubscribe($uid);
@@ -1267,7 +1460,7 @@ class OrdersController extends Controller
             //$change_pay_id = 12;
         }
         try {
-            $time = (int)date('H');
+            $time = (int)date('G');
             $change = false;
             if ($time <= 8 || $time >= 23) {
                 if (!$pay_info && $pay_merchant_id != $change_pay_id) {
@@ -1275,20 +1468,26 @@ class OrdersController extends Controller
                     $change = true;
                 }
             }
+            //$number,$template_type,$param=array()
             $phone_arr = ['15868100210', '18072713392', '15088790066', '13858057394', '18668029091', '18668420256'];
             //$phone_arr = ['18668029091'];
+
+            $param = ['pay_id'=>$pay_merchant_id];
             if ($n) {
-                $content = '支付通道:' . $pay_merchant_id . ',获取授权信息失败';
+                $template_type = 'pay_channel_remind';
+                //$content = '支付通道:' . $pay_merchant_id . ',获取授权信息失败';
             } else {
-                $content = '支付通道:' . $pay_merchant_id . ',订单号为' . $trade_no . '支付异常,异常信息:' . json_encode($pay_info);
+                $template_type = 'pay_channel_remind';
+                //$content = '支付通道:' . $pay_merchant_id . ',订单号为' . $trade_no . '支付异常,异常信息:' . json_encode($pay_info);
             }
             if ($change) {
-                $content .= ',已经切换到支付通道:' . $change_pay_id;
+                $template_type = 'pay_channel_change';
+                $param = ['pay_id'=>$pay_merchant_id,'new_pay_id'=>$change_pay_id];
             }
             foreach ($phone_arr as $phone) {
-                SMS::send($phone, $content);
+                AliSMS::send($phone, $template_type,$param);
             }
-            file_put_contents(date('Y-m-d') . '.txt', json_encode($pay_info), FILE_APPEND);
+
         } catch (\Exception $e) {
 
         }

+ 4 - 2
app/Http/Middleware/ReadOauth.php

@@ -140,12 +140,12 @@ class ReadOauth
                 }
             }
         }
-        //云栖测试
+        /*//云栖测试
         $qy_test_url = $this->yqTest($request,$uid_cookie,$distribution_channel_id);
         if($qy_test_url){
             //Log::info('url is: '.$qy_test_url);
             return redirect()->to($qy_test_url);
-        }
+        }*/
 
         //只能推送的统计
         $this->smartPush($request, $uid_cookie);
@@ -365,6 +365,8 @@ class ReadOauth
 
         ForceSubscribeService::tempForceSubscribeUsersLastTimeUpdate([
             'openid' => $openid,
+        	'appid' => $appid,
+        	'distribution_channel_id' => $distribution_channel_id,
             'last_interactive_time' => date('Y-m-d H:i:s')
         ]);
 

+ 1 - 0
app/Http/Routes/Wap/WapRoutes.php

@@ -36,6 +36,7 @@ Route::group(['domain'=>env('WAP_DOMAIN'),'namespace'=>'App\Http\Controllers\Wap
     Route::any('testLogin','Web\RedirectController@testLogin');
 
     Route::get('pay/wait','Pay\OrdersController@waitPage');
+    Route::get('pay/waitv2','Pay\OrdersController@waitPageV2');
 
     //链接强关跳转地址
     Route::get('subscribeauth','Subscribe\LinkSubscribeController@index');

+ 47 - 0
app/Libs/Pay/Merchants/PalmpayV2.php

@@ -0,0 +1,47 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2019/2/22
+ * Time: 18:11
+ */
+
+namespace App\Libs\Pay\Merchants;
+
+class PalmpayV2
+{
+    function __construct($config)
+    {
+        $this->appId = $config['appId'];
+        $this->mchId = $config['mchId'];
+        $this->appkey = $config['appKey'];
+        $this->subAppid = $config['subAppid'];
+    }
+
+    //生成订单
+    function send($data)
+    {
+        $data = [
+            'mchId'=>$this->mchId,
+            'appid'=>$this->appId,
+            'version'=>'3.0',
+            'productName'=>$data['body'],
+            'productDesc'=>'小说充值',
+            //'openid'=>$data['openid'],
+            //'subAppid'=>$this->subAppid,
+            'money'=>$data['price'],
+            'outTradeNo'=>$data['trade_no'],
+            'notifyUrl'=>env('PALMPAY_NOFITY_URL'),
+            'callbackUrl' => urlencode($data['pay_wait_url'])
+        ];
+        $data['sign'] = $this->sign($data);
+        $pay_url = "sdkServer/thirdpays/pay/WECHAT_SUB?".http_build_query($data);
+
+        return 'https://pay.palmpay.cn/'.$pay_url;
+    }
+
+    function sign($params)
+    {
+        return md5($params['appid'].'WECHAT_SUB'.$params['money'].$params['outTradeNo'].$this->appkey);
+    }
+}

+ 4 - 1
app/Libs/Pay/WechatPay.php

@@ -8,6 +8,7 @@ use App\Libs\Pay\Merchants\AllinPay;
 use App\Libs\Pay\Merchants\Official;
 use App\Libs\Pay\Merchants\LianLianPay;
 use App\Libs\Pay\Merchants\Palmpay;
+use App\Libs\Pay\Merchants\PalmpayV2;
 
 class WechatPay 
 {
@@ -26,7 +27,6 @@ class WechatPay
 				case 'YOULUO':
 					self::$_instance = new Youluo();
 					break;
-					
 				case 'ALLINPAY':
 					self::$_instance = new AllinPay($config);
 					break;
@@ -39,6 +39,9 @@ class WechatPay
                 case 'PALMPAY':
                     self::$_instance = new Palmpay($config);
                     break;
+                case 'PALMPAYV2':
+                    self::$_instance = new PalmpayV2($config);
+                    break;
                 default:
                     return null;
 			}