dever 7 years ago
parent
commit
c28579e4b1
2 changed files with 56 additions and 0 deletions
  1. 20 0
      applet/config/wechat.php
  2. 36 0
      applet/src/Code.php

+ 20 - 0
applet/config/wechat.php

@@ -102,4 +102,24 @@ $config['total_visit'] = array
 	),
 );
 
+$config['code'] = array
+(
+	'name' => '获取小程序码',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'scene' => 'param',
+		'page' => 'path',
+		'width' => 400,
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		'img' => true,
+	),
+);
+
 return $config;

+ 36 - 0
applet/src/Code.php

@@ -0,0 +1,36 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| 获取小程序二维码
+|--------------------------------------------------------------------------
+*/
+namespace Applet\Src;
+
+use Dever;
+use Main\Lib\Wechat;
+
+class Code
+{
+    public function get()
+    {
+        $project = Dever::input('project');
+        $param['path'] = Dever::input('path', 'pages/index/index');
+        $param['param'] = Dever::input('send');
+        $update = Dever::input('update', 2);
+
+        $file = Dever::pathDay('upload/applet/code', false) . $project . '_' . md5($param['path'] . '_' . $param['param']) . '.jpg';
+
+        if (!is_file($file) || $update == 1) {
+            $wechat = new Wechat($project, 'applet');
+
+            $data = $wechat->curl('code', $param, true);
+
+            if ($data) {
+                file_put_contents($file, $data);
+            }
+        }
+        $file = Dever::pic($file);
+
+        return $file;
+    }
+}