file('file'); $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/upload'; if(!file_exists($dir)){ //检查是否有该文件夹,如果没有就创建,并给予最高权限 mkdir($dir, 0777,true); } $ossClient = new OssClient(getConfigValue('storage_oss_keyid'), getConfigValue('storage_oss_secret'), getConfigValue('storage_oss_endpoint')); $info = $file->move($dir); if($info){ $newName = $info->getSaveName(); $storage_type = getConfigValue('storage_type'); if ($storage_type == 'oss'){ $file_path = dirname($_SERVER['SCRIPT_FILENAME']) . "/upload/".$newName; $result = $ossClient->uploadFile(getConfigValue('storage_oss_bucket'), $newName, $file_path); $data['url'] = $result['info']['url']; unlink($file_path); }elseif ($storage_type=='local'){ //压缩图片 //image_png_size_add(ROOT_PATH . 'public' . DS . 'uploads/images/'.$newName,ROOT_PATH . 'public' . DS . 'uploads/images/'.$newName); $data['url'] = 'http://'.$_SERVER['SERVER_NAME']."/upload/{$newName}"; } }else{ $this->error($file->getError()); } $this->success('上传成功',$data); } /** * @title 获取系统配置 * @desc 获取系统配置 * @url /api/Publics/config_info * @method POST * @tag 基础 * * @return name:agreement type:string desc:使用条款 * @return name:privacy type:string desc:隐私协议 * @return name:platform_agreement type:string desc:违规处罚 * @return name:about_us type:string desc:关于我们 * @return name:registration_agreement type:string desc:用户注册协议 * @return name:terms_service type:string desc:联通统一认证服务条款 * @return name:chain_on_query type:string desc:链上查询 * @return name:examples_illustrate type:string desc:转赠说明 * @return name:android_version type:string desc:安卓当前版本号 * @return name:android_package type:string desc:安卓包地址 * @return name:ios_package type:string desc:ios地址 **/ public function config_info(){ $nameArray = [ 'agreement', 'privacy', 'platform_agreement', 'about_us', 'registration_agreement', 'terms_service', 'chain_on_query', 'examples_illustrate', 'android_version', 'android_package', 'ios_package', 'free_lucky_number', 'lucky_recharge_price', 'service_fee', 'royalties', 'consignment', 'statement', 'invitation_background_img', 'share_background_img', 'new_instructions', 'share_switch' ]; $array = getConfig($nameArray); $this->success('成功',$array); } /** * @title 获取分享的签名 * @desc 获取分享的签名 * @url /api/Publics/getWechatSign * @method POST * @tag 基础 * **/ public function getWechatSign(){ $urls = input('url'); $appid = getConfigValue('wechat_appid'); $secret = getConfigValue('wechat_appsecret'); $redis = new Redis(); $access_token = $redis->get('access_token'); if (!$access_token){ $access_token = ''; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret"; $res=curlRequest($url); $res = json_decode($res,true); if (isset($res['access_token'])){ $redis->set('access_token',$res['access_token'],'7000'); $access_token = $res['access_token']; } } $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi"; $res2=curlRequest($url2); $res2 = json_decode($res2,true); if (!isset($res2) || $res2['errcode']!=0){ $this->error('获取ticket失败'); } $timestamp = time(); $noncestr = get32Str(15); // $urls = 'http://jybl.hdlkeji.com/web/h5/'; $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr×tamp=$timestamp&url=".$urls; $sign = sha1($string); $return = [ 'appid'=>$appid, 'noncestr'=>$noncestr, 'timestamp'=>$timestamp, 'url'=>$urls, 'sign'=>$sign, 'ticket'=>$res2['ticket'] ]; $this->success('成功',$return); } }