| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 | <?php/** * Created by PhpStorm. * User: z-yang * Date: 2019/7/25 * Time: 10:29 */namespace App\Http\Controllers\Wap\Pay;use App\Modules\Subscribe\Models\Order;use App\Modules\Subscribe\Services\OrderService;use App\Modules\Subscribe\Services\YearOrderService;use App\Modules\User\Services\UserMonthService;use App\Modules\User\Services\UserService;use GuzzleHttp\Client;use Illuminate\Routing\Controller;use Illuminate\Http\Request;use Log;class MonthOrderController extends Controller{    public function getH5RedirectUrl(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 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');        $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]);        }        $sign = _sign(compact('app_id','plan_id','user_id','change_type'),$key.$key);        $sign = strtoupper($sign);        $user_info = UserService::getById($user_id);        if($sign == $request->post('sign')){            UserMonthService::createSign($user_id,$plan_id,$change_type,$user_info->openid);        }        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');        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);            self::addOrderAndVip($user_id,$out_trade_no,$trade_no,$total_fee);        }        //}        Log::info('orderCallBack--------------------endend----------------------orderCallBack');        return response('success');    }    private function addOrderAndVip($uid,$out_trade_no,$trade_no,$price){        $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,0,$price,$out_trade_no,$trade_no);        YearOrderService::save_month_order([            'uid'=>$uid,            'distribution_channel_id'=>$user_info->distribution_channel_id,            'fee'=>$price / 100,            'send_order_id'=>0        ]);    }    private function createOrder($uid,$distribution_channel_id,$product_id,$price,$trade_no,$transaction_id){        $count = OrderService::getUserChargeTimes($uid);        $count = $count + 1;        $init_order = [            'distribution_channel_id' => $distribution_channel_id,            'uid' => $uid,            'product_id' => 6826,            'price' => $price / 100,            'pay_type' => $count,            'trade_no' => $trade_no,            'pay_merchant_source' => 'MONTH',            'pay_merchant_id' => 99,            'create_ip' => '',            'send_order_id' => '',            'send_order_name' => '',            'order_type' => 'MONTH_ORDER',            'from_bid' => '0',            'from_type' => 'auto_month',            '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);    }}
 |