| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | 获取小程序二维码
- |--------------------------------------------------------------------------
- */
- namespace Wechat_applet\Src;
- use Dever;
- use Token\Lib\Wechat;
- class Code
- {
- public function get($send = array())
- {
- $project = Dever::input('project');
- $param['path'] = Dever::input('path', 'pages/index/index');
- $param['param'] = Dever::input('send');
- $filename = Dever::input('filename');
- $param['width'] = Dever::input('width', 200);
- $param['is_hyaline'] = false;
- #正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
- $param['env_version'] = 'release';
- $update = Dever::input('update', 2);
- if ($send) {
- if (isset($send['project'])) {
- $project = $send['project'];
- }
- if (isset($send['path'])) {
- $param['path'] = $send['path'];
- }
- if (isset($send['send'])) {
- $param['param'] = $send['send'];
- }
- if (isset($send['width'])) {
- $param['width'] = $send['width'];
- }
- if (isset($send['env'])) {
- $param['env_version'] = $send['env'];
- }
- if (isset($send['filename'])) {
- $filename = $send['filename'];
- }
- if (isset($send['update'])) {
- $update = $send['update'];
- }
- }
- if (!$filename) {
- $filename = md5($param['param']);
- }
- $where['project_id'] = $project;
- $where['filename'] = $filename;
- $where['path'] = $param['path'];
- $where['send'] = $param['param'];
- $code = Dever::db('wechat_applet/code')->find($where);
- if (!$code) {
- $update = 1;
- } elseif ($update == 2) {
- return $code['file'] . '?v=' . time();
- }
-
- if ($update == 1) {
- $wechat = new Wechat($project, 'wechat_applet');
- $data = $wechat->curl('code', $param, true);
- if ($data) {
- $upload = Dever::load('upload/save')->copy('content,' . $data, 1, false, '', 'png', $filename);
- if (isset($upload['url'])) {
- $where['file'] = $upload['url'];
- $where['width'] = $param['width'];
- $where['env'] = $param['env_version'];
- if ($code) {
- $where['where_id'] = $code['id'];
- Dever::db('wechat_applet/code')->update($where);
- } else {
- Dever::db('wechat_applet/code')->insert($where);
- }
-
- return $upload['url'] . '?v=' . time();
- }
- }
- }
- return false;
- /*
- $file = Dever::pathDay('upload/applet/code', false) . $project . '_' . md5($param['path'] . '_' . $param['param'] . '_' . $param['width']) . '.jpg';
- if (!is_file($file) || $update == 1) {
- $wechat = new Wechat($project, 'wechat_applet');
- $data = $wechat->curl('code', $param, true);
- if ($data) {
- file_put_contents($file, $data);
- }
- }
- //$host = str_replace(DEVER_PROJECT . '/' . DEVER_APP_NAME . '/', '', Dever::config('host')->base);
- $host = Dever::config('host')->host;
- if (strstr($file, '/share/dc/data/')) {
- return $host . str_replace('/share/dc/data/', '', $file);
- }
- return $host . str_replace(DEVER_PROJECT_PATH, '', $file);
- $file = Dever::pic($file);
- return $file;
- */
- }
- }
|