get($url)->getBody()->getContents(); } public function getWechatRedirectUrl(Request $request) { $app_id = 'Aekgrv87yo5wxnl715'; $app_secret = '57gwsnd158ib2sn7wluq5716brp8fzm'; $key = 'sn7wluq5716brp8fzm'; //$plan_id = 124768; $plan_id = 39603; $user_id = 10008; $ip = _getIp(); $sign = _sign(compact('app_id', 'app_secret', 'plan_id', 'user_id', 'ip'), $key . $key); $sign = strtoupper($sign); $client = new Client(); Log::info(compact('app_id', 'app_secret', 'plan_id', 'user_id', 'ip', 'sign')); //$url = 'http://pap.manyuedu.org/h5.php?'.http_build_query(compact('app_id','app_secret','plan_id','user_id','ip','sign')); $url = 'http://pap.manyuedu.org/?' . http_build_query(compact('app_id', 'app_secret', 'plan_id', 'user_id', 'ip', 'sign')); return $client->get($url)->getBody()->getContents(); } public function signCallBack(Request $request) { Log::info('signCallBack------------------------------------------signCallBack'); Log::info($request->all()); Log::info($request->getMethod()); //$key = 'sn7wluq5716brp8fzm'; $key = env('MONTH_ORDER_KEY'); $app_id = $request->post('app_id'); $plan_id = $request->post('plan_id'); $type = 'MONTH'; if($plan_id == env('MONTH_ORDER_PLAN_ID')){ $type = 'MONTH'; } if($plan_id == env('MONTH_WEEK_ORDER_PLAN_ID')){ $type = 'WEEK'; } $user_id = $request->post('user_id'); $change_type = $request->post('change_type'); if ($check = checkParam($request->except('_url'), ['app_id', 'plan_id', 'user_id', 'change_type'])) { //return response()->error('PARAM_EMPTY', ['msg' => $check]); return response('fail'); } $sign = _sign(compact('app_id', 'plan_id', 'user_id', 'change_type'), $key . $key); $sign = strtoupper($sign); $user_info = UserService::getById($user_id); if (!$user_info) { Log::error('signCallBack user is not exist,uid is :' . $user_id); return response('fail'); } if ($sign == $request->post('sign')) { UserMonthService::createSign($user_id, $plan_id, $change_type, $user_info->openid,$type); } Log::info('signCallBack-------------------end-----------------------signCallBack'); return response('success'); } public function orderCallBack(Request $request) { Log::info('orderCallBack------------------------------------------orderCallBack'); Log::info($request->all()); Log::info($request->getMethod()); $key = env('MONTH_ORDER_KEY');//'sn7wluq5716brp8fzm'; $app_id = $request->post('app_id'); $plan_id = $request->post('plan_id', 0); $user_id = $request->post('user_id'); $total_fee = $request->post('total_fee'); $trade_no = $request->post('trade_no'); $out_trade_no = $request->post('out_trade_no'); $result_code = $request->post('result_code',0); $type = 'MONTH'; $product_id = 6826; if($plan_id == env('MONTH_ORDER_PLAN_ID')){ $type = 'MONTH'; $product_id = 6826; } if($plan_id == env('MONTH_WEEK_ORDER_PLAN_ID')){ $type = 'WEEK'; $product_id =7394; } $this->recordOrderCallBack($request,$type); if(!$result_code) return response('success'); if ($check = checkParam($request->except('_url'), ['app_id', 'user_id', 'total_fee', 'trade_no', 'out_trade_no'])) { return response()->error('PARAM_EMPTY', ['msg' => $check]); } $sign = _sign(compact('app_id', 'user_id', 'total_fee', 'trade_no', 'out_trade_no'), $key . $key); $sign = strtoupper($sign); //if($sign == $request->post('sign')){ if (!UserMonthService::getOrderByOrder($trade_no, $out_trade_no)) { UserMonthService::createLOrder($user_id, $plan_id, $total_fee, $trade_no, $out_trade_no,$type); $this->addOrderAndVip($user_id, $out_trade_no, $trade_no, $total_fee,$product_id,$type); $this->successPayPushMsg($user_id,$type); $this->userProperty($user_id); } //} Log::info('orderCallBack--------------------endend----------------------orderCallBack'); return response('success'); } private function addOrderAndVip($uid, $out_trade_no, $trade_no, $price,$product_id,$type) { $order_info = OrderService::getByTradeNo($out_trade_no); //订单已经存在 if ($order_info) { return; } $user_info = UserService::getById($uid); if (!$user_info) return; $this->createOrder($uid, $user_info->distribution_channel_id, $product_id, $price, $out_trade_no, $trade_no,$type); if($type == 'MONTH'){ YearOrderService::save_month_order([ 'uid' => $uid, 'distribution_channel_id' => $user_info->distribution_channel_id, 'fee' => $price / 100, 'send_order_id' => 0 ]); } if($type == 'WEEK'){ YearOrderService::save_vip_order_daynum([ 'uid' => $uid, 'distribution_channel_id' => $user_info->distribution_channel_id, 'fee' => $price / 100, 'send_order_id' => 0, 'day_num'=>7 ]); } } private function createOrder($uid, $distribution_channel_id, $product_id, $price, $trade_no, $transaction_id,$type) { $count = OrderService::getUserChargeTimes($uid); $count = $count + 1; $send_order_id = 0; try { $send_order_id = (int)Redis::hget('book_read:' . $uid, 'send_order_id'); } catch (\Exception $e) { } $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; } } $from_bid = ReadRecordService::getSimpleFirstReadRecord($uid); $init_order = [ 'distribution_channel_id' => $distribution_channel_id, 'uid' => $uid, 'product_id' => $product_id, 'price' => $price / 100, 'pay_type' => $count, 'trade_no' => $trade_no, 'pay_merchant_source' => $type, 'pay_merchant_id' => 99, 'create_ip' => '', 'send_order_id' => $send_order_id, 'send_order_name' => $send_order_name, 'order_type' => 'RECHARGE', 'from_bid' => $from_bid, 'from_type' => 'auto_'.strtolower($type), 'activity_id' => 0, 'inner_send_order_id' => '', 'status' => 'PAID', 'transaction_id' => $transaction_id, 'pay_end_at' => date('Y-m-d H:i:s') ]; OrderService::save_order($init_order); } public function wait(Request $request) { //$user_cookie = \Cookie::get(env('COOKIE_AUTH_WEB_WECHAT')); //$uid = $user_cookie ? decrypt($user_cookie) : null; $r = $request->get('r'); $r = urldecode($r); return view('pay.order.monthpaywait', ['url' => $r]); } public function issuccess(Request $request) { $uid = \Cookie::get(env('COOKIE_AUTH_WEB_WECHAT')); //$uid = $user_cookie ? decrypt($user_cookie) : null; if (!$uid) { return response()->success(); } $last = UserMonthService::getLastOrder($uid); if (!$last) { return response()->error('WAP_SYS_ERROR'); } if (time() - strtotime($last->created_at) < 20) { return response()->success(); } return response()->error('WAP_SYS_ERROR'); } private function recordOrderCallBack(Request $request,$type){ $app_id = $request->post('app_id',''); $plan_id = $request->post('plan_id',0); $uid = $request->post('user_id',''); $total_fee = $request->post('total_fee',0); $trade_no = $request->post('trade_no',''); $out_trade_no = $request->post('out_trade_no',''); $result_code = $request->post('result_code',-1); $sign = $request->post('sign',-1); $created_at = date('Y-m-d H:i:s'); $updated_at = date('Y-m-d H:i:s'); $origin_data = json_encode($request->except('_url')); try{ DB::table('user_month_order_callback')->insert([ compact('uid','app_id','plan_id','total_fee','out_trade_no','origin_data', 'trade_no','result_code','sign','created_at','updated_at','type' ) ]); }catch (\Exception $e){ Log::error('recordOrderCallBack error'); } } protected function successPayPushMsg($uid,$type) { try { $force_sub_info = DB::table('force_subscribe_users')->where('uid', $uid)->where('is_subscribed', 1)->first(); $data = UserService::getById($uid); if (!$force_sub_info) { return; } $content_format = ''; if($type == 'MONTH'){ $content_format = "包月购买成功通知:\r\n购买类型: 30元包月\r\n>点击继续上次阅读\r\n包月特权:\r\n 💝 全站所有作品免费阅读\r\n 💝 全站无广告\r\n 💝 阅读管家1对1服务\r\n为保障包月权益,请置顶公众号 "; } if($type == 'WEEK'){ $content_format = "包周购买成功通知:\r\n购买类型: 7元包月\r\n>点击继续上次阅读\r\n包月特权:\r\n 💝 全站所有作品免费阅读\r\n 💝 全站无广告\r\n 💝 阅读管家1对1服务\r\n为保障包周权益,请置顶公众号 "; } $delay = 0; $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($data->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/continue';; $top_url = 'https://help.zhuishuyun.com/top.html'; $content = sprintf($content_format, $url, $top_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('month_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::error('pay_success_push error'); Log::error($e); } return; } private function userProperty($uid){ try{ $userproperty = UserDivisionCpcPropertyService::calculateUserPropertyV2($uid); if(!$userproperty) { return ; } UserDivisionCpcPropertyService::createorUpdateV2($userproperty); }catch (\Exception $e){ Log::error('month userProperty error'); Log::error($e); } } }