<?php

namespace App\Http\Controllers\Wap\Other;

use App\Http\Controllers\Wap\BaseController;
use App\Http\Controllers\Controller;
use App\Modules\Book\Services\ChapterShareWechatConfigService;
use Illuminate\Http\Request;

class WeixinController extends Controller
{

    public function jsSdkConfig(Request $request,$channel_id,$doamin)
    {
        //$base_url =   env('PROTOCOL').'://site'.$channel_id.'.'.$doamin.'.com/';
        $url = $request->post('url');
        if($url) $url = urldecode($url);
        $appid = 'wx32473d47826d656f';
        $appSecret = '2aa0e49566adf24e6415e8c0d1698a89';
        $config = new ChapterShareWechatConfigService($appid,$appSecret);
        //$config->setAccessToken('');
        $config->requestAccessToken();
        $config->requestJsApiTicket();
        //$url = $base_url.$path;
        $data = $config->getJssdkConfig($url);
        return response()->success($data);
    }

    public function shareLink(Request $request){
        $openid = $request->get('openid');
        $redirect = $request->get('redirect');
        $redirect  =urlencode($redirect);
        $url = env('XIYUE_HOST').'?openid='.$openid.'&zs_redirect='.$redirect;
        return redirect()->to($url);
    }
}
