123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace app\api\controller\applets;
- use app\api\controller\ZskkDefaultController;
- use app\api\servies\applets\AppletsService;
- use app\api\servies\Butt\ButtService;
- use app\api\utils\UUIDUtils;
- use app\common\library\uploadToCloud;
- use think\facade\Config;
- /*
- * 微信小程序接口
- */
- class AppletsController extends ZskkDefaultController
- {
- protected $needToken = true;
- protected $logName = "AppletsController";
- public function application_start(AppletsService $service)
- {
- try{
- $params = $this->getParams();
- $doctor = $this->getCache($this->getToken());
- $return = $service->application_start($params,$doctor);
- return $this->success($return);
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- public function myApplication(AppletsService $service)
- {
- try{
- $params = $this->getParams();
- $doctor = $this->getCache($this->getToken());
- $return = $service->getMyApplication($params,$doctor);
- return $this->success($return);
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- public function save_autograph(AppletsService $service)
- {
- $params = $this->getParams();
- if(empty($params['attachment']))
- {
- $this->throwError('找不到需要上传的文件','0009');
- }
- $attachment = explode('base64,',$params['attachment']);
- $image = $attachment[1];
- $file = base64_decode($image);
- if($file) {
- $name = UUIDUtils::uuid().'.png';
- $path = ROOT_PATH . 'public' . DS . 'uploads'. DS .$name;
- $url = '/' . 'autograph' . '/' .$name;
- $r = file_put_contents($path, $file);
- if (!$r) {
- $this->throwError('图片生成失败','0008');
- }else {
- $doctor = $this->getCache($this->getToken());
- $type = Config::get('upload');
- if($type == 1)
- {
- $r = $service->save_autograph($url,$doctor);
- $success = ['url'=>$url,'type'=>$type,'tokenUrl'=>$url];
- return $this->success($success);
- }
- $key = 'autograph/' . $name;
- $source_file = './' . 'uploads' . '/' . $name;
- $upload = new uploadToCloud();;
- $s = $upload->upload($key,$source_file);
- if(($s['@metadata']['statusCode'] ?? '') == '200')
- {
- $r = $service->save_autograph($url,$doctor);
- gc_collect_cycles();
- unset($info);
- unlink($source_file);
- $success = ['url'=>$key,'type'=>'2','tokenUrl'=>$upload->makeUrl($key)];
- return $this->success($success);
- }else{
- return '上传云失败';
- }
- // return $this->success($url);
- }
- }else{
- $this->throwError('无法获取上传的文件','0009');
- }
- }
- public function autograph_switch(AppletsService $service)
- {
- $params = $this->getParams();
- $doctor = $this->getCache($this->getToken());
- $info = $service->autograph_switch($doctor,$params['is_use_autograph']);
- return $this->success($info);
- }
- public function getAutograph(AppletsService $service)
- {
- $doctor = $this->getCache($this->getToken());
- if(empty($doctor))
- {
- $this->throwError('无效的token,请重新进行登陆','0099');
- }
- $data = $service->getAutograph($doctor['id']);
- $data['autograph_url'] = $data['autograph'];
- if($data['autograph_type'] == 2)
- {
- $data['autograph_url'] = $this->makeFileUrl($data['autograph'],$data['autograph_type']);
- }
- return $this->success($data);
- }
- }
|