├── wechat_mini_program ├── pages │ ├── info │ │ ├── info.json │ │ ├── info.wxss │ │ ├── info.wxml │ │ └── info.js │ └── scan │ │ ├── scan.json │ │ ├── scan.wxml │ │ └── scan.js ├── images │ ├── bg.jpg │ ├── logo.jpg │ └── logo.png ├── cloud_function │ └── caozha_ai_shiwu │ │ ├── config.json │ │ ├── package.json │ │ └── index.js ├── sitemap.json ├── app.json ├── app.wxss ├── utils │ └── util.js ├── project.config.json └── app.js ├── PHP ├── access_token.php ├── config.php └── AccessToken_get.php ├── .gitattributes ├── README.md └── LICENSE /wechat_mini_program/pages/info/info.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /wechat_mini_program/pages/scan/scan.json: -------------------------------------------------------------------------------- 1 | { 2 | } -------------------------------------------------------------------------------- /wechat_mini_program/images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dengcao/AI-Intelligent-Recognition/master/wechat_mini_program/images/bg.jpg -------------------------------------------------------------------------------- /wechat_mini_program/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dengcao/AI-Intelligent-Recognition/master/wechat_mini_program/images/logo.jpg -------------------------------------------------------------------------------- /wechat_mini_program/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dengcao/AI-Intelligent-Recognition/master/wechat_mini_program/images/logo.png -------------------------------------------------------------------------------- /PHP/access_token.php: -------------------------------------------------------------------------------- 1 | {"access_token":"24.04339w6d0c05h55d1fc7e9c4d417d.259d2000.1589767726.288835-16855940","expire_time":1589767726} -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=JavaScript 2 | *.wxss linguist-language=JavaScript 3 | *.wxml linguist-language=JavaScript 4 | *.php linguist-language=PHP 5 | -------------------------------------------------------------------------------- /wechat_mini_program/cloud_function/caozha_ai_shiwu/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "caozha_ai_shiwu": [ 4 | "security.imgSecCheck" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /wechat_mini_program/sitemap.json: -------------------------------------------------------------------------------- 1 | { 2 | "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", 3 | "rules": [{ 4 | "action": "allow", 5 | "page": "*" 6 | }] 7 | } -------------------------------------------------------------------------------- /wechat_mini_program/cloud_function/caozha_ai_shiwu/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "caozha_ai_shiwu", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "wx-server-sdk": "~1.8.3" 13 | } 14 | } -------------------------------------------------------------------------------- /wechat_mini_program/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages": [ 3 | "pages/scan/scan", 4 | "pages/info/info" 5 | ], 6 | "window": { 7 | "backgroundTextStyle": "light", 8 | "navigationBarBackgroundColor": "#19be6b", 9 | "navigationBarTitleText": "AI智能识物", 10 | "navigationBarTextStyle": "white" 11 | }, 12 | "sitemapLocation": "sitemap.json", 13 | "navigateToMiniProgramAppIdList": [ 14 | "wx9588ff2d3063ee31" 15 | ] 16 | } -------------------------------------------------------------------------------- /wechat_mini_program/app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | .container { 3 | height: 100%; 4 | display: flex; 5 | flex-direction: column; 6 | align-items: center; 7 | justify-content: space-between; 8 | padding: 200rpx 0; 9 | box-sizing: border-box; 10 | } 11 | .banquan{ 12 | clear: both; 13 | padding: 150rpx 0 80rpx 0; 14 | text-align:center; 15 | font-size: 12px; 16 | color:#fff; 17 | font-family:Arial, Helvetica, sans-serif; 18 | } -------------------------------------------------------------------------------- /wechat_mini_program/utils/util.js: -------------------------------------------------------------------------------- 1 | const formatTime = date => { 2 | const year = date.getFullYear() 3 | const month = date.getMonth() + 1 4 | const day = date.getDate() 5 | const hour = date.getHours() 6 | const minute = date.getMinutes() 7 | const second = date.getSeconds() 8 | 9 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') 10 | } 11 | 12 | const formatNumber = n => { 13 | n = n.toString() 14 | return n[1] ? n : '0' + n 15 | } 16 | 17 | module.exports = { 18 | formatTime: formatTime 19 | } 20 | -------------------------------------------------------------------------------- /PHP/config.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 拍照智能识物 12 | 可识别地标、车型、花卉、植物、动物、果蔬、货币、红酒、食材等等,AI智能技术识别准确度高。 13 | 14 | 15 | 16 | 19 | 20 | 从相册选择> 21 | {{id}} 22 | 23 | 24 | 25 | 26 | @工具大全 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /wechat_mini_program/pages/info/info.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 识别结果(共{{result_num}}条) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | @工具大全 caozha.com 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /wechat_mini_program/cloud_function/caozha_ai_shiwu/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 3 | ☆ ☆ 4 | ☆ 系 统:AI智能识物 ☆ 5 | ☆ 日 期:2019-07 ☆ 6 | ☆ 开 发:草札(www.caozha.com) ☆ 7 | ☆ 鸣 谢:穷店(www.qiongdian.com) 品络(www.pinluo.com) ☆ 8 | ☆ 声 明: 使用本程序源码必须保留此版权声明等相关信息! ☆ 9 | ☆ Copyright ©2020 www.caozha.com All Rights Reserved. ☆ 10 | ☆ ☆ 11 | ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 12 | */ 13 | const cloud = require('wx-server-sdk') 14 | cloud.init() 15 | exports.main = async (event) => { 16 | try { 17 | let result = ''; 18 | if(event.content){ 19 | result = await cloud.openapi.security.msgSecCheck({ 20 | content: event.content 21 | }); 22 | }else if(event.base64){ 23 | result = await cloud.openapi.security.imgSecCheck({ 24 | media: { 25 | contentType: 'image/png', 26 | value: Buffer.from(event.base64, 'base64') 27 | } 28 | }) 29 | } 30 | return { 31 | result 32 | } 33 | } catch (error) { 34 | return { 35 | error 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AI智能识物 2 | 3 | AI智能识物,是一款实用的小程序。可以拍照智能识物,可识别地标、车型、花卉、植物、动物、果蔬、货币、红酒、食材等等,AI智能技术识别准确度高。 4 | 5 | ### 更新说明: 6 | 7 | 此源码为1.2.0版本。 8 | 9 | 主要更新内容:新增security.imgSecCheck函数对用户上传的图片进行合法性安全检测。 10 | 11 | 支持本程序,请到Gitee和GitHub给我们点Star! 12 | 13 | Gitee:https://gitee.com/dengzhenhua/AI-Intelligent-Recognition 14 | 15 | GitHub:https://github.com/dengcao/AI-Intelligent-Recognition 16 | 17 | ### 安装方法 18 | 19 | 1、PHP端: 20 | 21 | 打开PHP后端目录/PHP/,找到config.php,修改为您的API信息,并将PHP代码上传到您的网站空间或者服务器。获得一个URL:http://xxxxx/AccessToken_get.php 22 | 23 | 2、小程序端: 24 | 25 | ①打开微信小程序目录/wechat_mini_program/,找到app.js,并找到代码: 26 | 27 | url: "https://caozha.com/xxxxx/AccessToken_get.php", 28 | 29 | 将上面代码的URL替换为您网站的URL。 30 | 31 | ②在cloud_function目录,有一个云函数caozha_ai_shiwu。在微信开发者工具里,在文件夹caozha_ai_shiwu上点击右键,将此云函数上传并部署到您的小程序云端。 32 | 33 | 如果您没有开通微信小程序的云端开发,点击“云开发”开通。关于云函数:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/functions.html 34 | 35 | ----------------------- 36 | 37 | 特别说明:采用PHP+小程序结合的方式,是因为百度API获取的Access Token有效期为1个月,时效足够长,用自己的服务器可以重复使用此Access Token,避免访问量大的时候频繁请求百度API而被拒绝。 38 | 39 | ### 关于 40 | 41 | 开发:[邓草博客 blog.5300.cn](http://blog.5300.cn) 42 | 43 | 赞助:[品络互联 www.pinluo.com](http://www.pinluo.com)   [AI工具箱 5300.cn](http://5300.cn)   [汉语言文学网 hyywx.com](http://hyywx.com)   [雄马 xiongma.cn](http://xiongma.cn)   [优惠券 tm.gs](http://tm.gs) 44 | 45 | 46 | ### 扫码体验 47 | ![输入图片说明](https://images.gitee.com/uploads/images/2020/0430/104457_0326c9b6_7397417.jpeg "小程序码") 48 | 49 | ### 界面预览 50 | 51 | ![输入图片说明](https://images.gitee.com/uploads/images/2020/0430/104726_cf775e8c_7397417.png "AI智能识物首页") 52 | ![输入图片说明](https://images.gitee.com/uploads/images/2020/0504/200311_1fa465ba_7397417.png "测试结果1") 53 | ![输入图片说明](https://images.gitee.com/uploads/images/2020/0504/200649_2f1b2f64_7397417.jpeg "测试结果2") 54 | ![输入图片说明](https://images.gitee.com/uploads/images/2020/0504/200702_72e4ba6f_7397417.jpeg "测试结果3") 55 | -------------------------------------------------------------------------------- /wechat_mini_program/pages/info/info.js: -------------------------------------------------------------------------------- 1 | /* 2 | ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 3 | ☆ ☆ 4 | ☆ 系 统:AI智能识物 ☆ 5 | ☆ 日 期:2019-07 ☆ 6 | ☆ 开 发:草札(www.caozha.com) ☆ 7 | ☆ 鸣 谢:穷店(www.qiongdian.com) 品络(www.pinluo.com) ☆ 8 | ☆ 声 明: 使用本程序源码必须保留此版权声明等相关信息! ☆ 9 | ☆ Copyright ©2020 www.caozha.com All Rights Reserved. ☆ 10 | ☆ ☆ 11 | ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 12 | */ 13 | Page({ 14 | data: { 15 | imgurl: "", 16 | itemData: [] 17 | }, 18 | banquan: function () { 19 | wx.navigateToMiniProgram({ 20 | appId: 'wx9588ff2d3063ee31', 21 | path: '', 22 | envVersion: 'release', 23 | success(res) { 24 | // 打开成功 25 | } 26 | }) 27 | }, 28 | onLoad: function() { 29 | var res_imgurl = wx.getStorageSync("res_imgurl"); 30 | var res_data = wx.getStorageSync("res_data"); 31 | //res_data = res_data.toString();//强制转换为字符串 32 | res_data.replace(RegExp("http", "g"), "https");//全部替换 33 | console.log("替换后:"+res_data); 34 | res_data = JSON.parse(res_data); 35 | 36 | var itemData = res_data["result"]; 37 | this.setData({ 38 | imgurl: res_imgurl, 39 | itemData: itemData, 40 | result_num: res_data["result_num"] 41 | }); 42 | for (var a = this.data.itemData, s = [], e = 0, o = a.length; e < o; e++) { 43 | var i = (100 * Number(a[e].score)).toFixed(2); 44 | s.push(i); 45 | } 46 | this.setData({ 47 | score: s 48 | }), console.log(this.data.itemData); 49 | 50 | } 51 | }); -------------------------------------------------------------------------------- /wechat_mini_program/app.js: -------------------------------------------------------------------------------- 1 | //app.js 2 | /* 3 | ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 4 | ☆ ☆ 5 | ☆ 系 统:AI智能识物 ☆ 6 | ☆ 日 期:2019-07 ☆ 7 | ☆ 开 发:草札(www.caozha.com) ☆ 8 | ☆ 鸣 谢:穷店(www.qiongdian.com) 品络(www.pinluo.com) ☆ 9 | ☆ 声 明: 使用本程序源码必须保留此版权声明等相关信息! ☆ 10 | ☆ Copyright ©2020 www.caozha.com All Rights Reserved. ☆ 11 | ☆ ☆ 12 | ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 13 | */ 14 | App({ 15 | onLaunch: function () { 16 | 17 | //获取当前时间戳 18 | var timestamp = Date.parse(new Date()); 19 | timestamp = timestamp / 1000; 20 | console.log("当前时间戳为:" + timestamp); 21 | 22 | var baiduyun = wx.getStorageSync("baiduyun_AccessToken"); 23 | console.log(baiduyun.access_token + " " + baiduyun.expires_in); 24 | 25 | if (baiduyun.access_token == "" || baiduyun.access_token == null || baiduyun.expires_in == "" || baiduyun.expires_in == null || baiduyun.expires_in < timestamp){ 26 | wx.request({ 27 | url: "https://caozha.com/xxxxx/AccessToken_get.php", 28 | data: {}, 29 | method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT 30 | header: { 31 | //"Content-Type":"application/json" 32 | //'content-type': 'application/x-www-form-urlencoded' 33 | }, // 设置请求的 header 34 | 35 | success: function (res) { 36 | console.info(res.data); 37 | wx.setStorageSync("baiduyun_AccessToken", res.data); 38 | }, 39 | fail: function (res) { 40 | // fail 41 | wx.showModal({ 42 | title: "提示", 43 | content: "获取AccessToken出错,程序可能无法正常运行。", 44 | showCancel: false, 45 | success: function (res) { 46 | if (res.confirm) { 47 | } else if (res.cancel) { 48 | } 49 | } 50 | }) 51 | }, 52 | complete: function (res) { 53 | // complete 54 | } 55 | }); 56 | } 57 | wx.cloud.init({ 58 | traceUser: true, 59 | }) 60 | }, 61 | globalData: { 62 | userInfo: null 63 | } 64 | }) -------------------------------------------------------------------------------- /PHP/AccessToken_get.php: -------------------------------------------------------------------------------- 1 | " . $content);//写入配置文件 44 | /*$fp = fopen($filename, "w"); 45 | fwrite($fp, "" . $content); 46 | fclose($fp);*/ 47 | } 48 | 49 | 50 | function getAccessToken($client_id,$client_secret) { 51 | // access_token 应该全局存储与更新,以下代码以写入到文件中做示例 52 | $data = json_decode(get_php_file("access_token.php")); 53 | 54 | if ($data->expire_time < time()) { 55 | $url = 'https://aip.baidubce.com/oauth/2.0/token'; 56 | $post_data['grant_type'] = 'client_credentials'; 57 | $post_data['client_id'] = $client_id;//你的 Api Key 58 | $post_data['client_secret'] = $client_secret;//你的 Secret Key 59 | $o = ""; 60 | foreach ( $post_data as $k => $v ) 61 | { 62 | $o.= "$k=" . urlencode( $v ). "&" ; 63 | } 64 | $post_data = substr($o,0,-1); 65 | 66 | $res = request_post($url, $post_data); 67 | 68 | $arr=json_decode($res,true); 69 | //var_dump($res); 70 | 71 | //$accesstoken_arr=array("access_token"=>$arr["access_token"],"expires_in"=>$arr["expires_in"],"error"=>$arr["error"],"error_description"=>$arr["error_description"]); 72 | //echo json_encode($dwz_arr); 73 | 74 | 75 | $access_token = $arr["access_token"]; 76 | $expires_in=time()+$arr["expires_in"]; 77 | if ($access_token) { 78 | $data->expire_time = $expires_in; 79 | $data->access_token = $access_token; 80 | set_php_file("access_token.php", json_encode($data)); 81 | } 82 | } else { 83 | $access_token = $data->access_token; 84 | $expires_in=$data->expire_time; 85 | } 86 | 87 | $accesstoken_arr=array("access_token"=>$access_token,"expires_in"=>$expires_in); 88 | return $accesstoken_arr; 89 | } 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /wechat_mini_program/pages/scan/scan.js: -------------------------------------------------------------------------------- 1 | /* 2 | ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 3 | ☆ ☆ 4 | ☆ 系 统:AI智能识物 ☆ 5 | ☆ 日 期:2019-07 ☆ 6 | ☆ 开 发:草札(www.caozha.com) ☆ 7 | ☆ 鸣 谢:穷店(www.qiongdian.com) 品络(www.pinluo.com) ☆ 8 | ☆ 声 明: 使用本程序源码必须保留此版权声明等相关信息! ☆ 9 | ☆ Copyright ©2020 www.caozha.com All Rights Reserved. ☆ 10 | ☆ ☆ 11 | ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 12 | */ 13 | Page({ 14 | data: {}, 15 | PlantDetect: function(n) { 16 | 17 | var baiduyun = wx.getStorageSync("baiduyun_AccessToken"); 18 | 19 | var o = n.currentTarget.id; 20 | 21 | let that = this; 22 | wx.chooseImage({ 23 | count: 1, 24 | sizeType: [ "compressed" ], 25 | sourceType: [ o ], 26 | success: function (res) { 27 | var img_file = res.tempFilePaths[0]; 28 | wx.setStorageSync("res_imgurl", img_file); 29 | console.log("上传时:"+res.tempFilePaths[0]) //最终图片路径 30 | 31 | //-----返回选定照片的本地文件路径列表,获取照片信息----------- 32 | wx.showLoading({ 33 | title: "正在识别,请稍候" 34 | }),wx.getImageInfo({ 35 | src: img_file, 36 | success: res_1 => { 37 | //---------利用canvas压缩图片-------------- 38 | var ratio = 2; 39 | var canvasWidth = res_1.width //图片原始长宽 40 | var canvasHeight = res_1.height 41 | while (canvasWidth > 500 || canvasHeight > 500) { // 保证宽高在400以内 42 | canvasWidth = Math.trunc(res_1.width / ratio) 43 | canvasHeight = Math.trunc(res_1.height / ratio) 44 | ratio++; 45 | } 46 | 47 | //----------绘制图形并取出图片路径-------------- 48 | var ctx = wx.createCanvasContext('canvas') 49 | ctx.drawImage(res_1.path, 0, 0, canvasWidth, canvasHeight) 50 | ctx.draw(false, setTimeout(function() { 51 | wx.canvasToTempFilePath({ 52 | canvasId: 'canvas', 53 | destWidth: canvasWidth, 54 | destHeight: canvasHeight, 55 | success: res_2 => { 56 | console.log("压缩后:"+res_2.tempFilePath) //最终图片路径 57 | console.log("宽:"+canvasWidth+" 高:"+canvasHeight) //最终图片路径 58 | /* 59 | wx.getImageInfo({ 60 | src: res_2.tempFilePath, 61 | success: res_3 => { 62 | }}) 63 | */ 64 | 65 | 66 | wx.getFileSystemManager().readFile({ 67 | filePath: res_2.tempFilePath, //选择图片返回的相对路径 68 | encoding: 'base64', //编码格式 69 | success: res_last => { //成功的回调 70 | 71 | console.log('data:image/png;base64,' + res_last.data); 72 | //Base64编码字符串,以图片文件形式请求时必填。(支持图片格式:jpg,bmp,png,jpeg),图片大小不超过4M。最短边至少15px,最长边最大4096px。注意:图片需要base64编码、去掉编码头后再进行urlencode。 73 | 74 | wx.cloud.callFunction({ 75 | name: "caozha_ai_shiwu", 76 | data: { 77 | base64: res_last.data, 78 | } 79 | }).then((res2) => { 80 | console.log('imgSecCheck =', res2) 81 | try{ 82 | 83 | if (res2.result.result.errCode == 0) { 84 | 85 | // 图片合法 86 | wx.request({ 87 | //开发文档https://cloud.baidu.com/doc/IMAGERECOGNITION/ImageClassify-API.html#.E8.AF.B7.E6.B1.82.E8.AF.B4.E6.98.8E 88 | url: "https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general?access_token=" + baiduyun.access_token, 89 | data: { image: res_last.data, baike_num:20 }, 90 | dataType: 'text',//不对返回的内容进行 JSON.parse 91 | method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT 92 | header: { 93 | //"Content-Type":"application/json" 94 | 'content-type': 'application/x-www-form-urlencoded' 95 | }, // 设置请求的 header 96 | 97 | success: function (res) { 98 | 99 | var res_data = res.data; 100 | 101 | //var res_data = res.data.toString();//强制转换为字符串 102 | //res_data.replace('http:', 'https:'); 103 | //res_data = JSON.parse(res_data); 104 | 105 | console.log("JSON:"+res_data); 106 | //console.info(res_data); 107 | wx.setStorageSync("res_data", res_data); 108 | wx.navigateTo({ 109 | url: "../info/info" 110 | }); 111 | }, 112 | fail: function (res) { 113 | // fail 114 | wx.showModal({ 115 | title: "提示", 116 | content: "获取出错,请重试", 117 | showCancel: false, 118 | success: function (res) { 119 | if (res.confirm) { 120 | } else if (res.cancel) { 121 | } 122 | } 123 | }) 124 | }, 125 | complete: function (res) { 126 | // complete 127 | wx.hideLoading(); 128 | } 129 | }); 130 | 131 | 132 | }else{ 133 | 134 | 135 | // 图片非法 136 | wx.showModal({ 137 | title: "错误提示", 138 | content: "选择的图片有非法内容,请重新选个图片再试。", 139 | showCancel: false, 140 | success: function (res) { 141 | if (res.confirm) { 142 | } else if (res.cancel) { 143 | } 144 | } 145 | }) 146 | 147 | } 148 | 149 | }catch(err){ 150 | 151 | // 图片非法 152 | wx.showModal({ 153 | title: "错误提示", 154 | content: "选择的图片有非法内容,请重新选个图片再试。", 155 | showCancel: false, 156 | success: function (res) { 157 | if (res.confirm) { 158 | } else if (res.cancel) { 159 | } 160 | } 161 | }) 162 | 163 | } 164 | 165 | }) 166 | 167 | 168 | 169 | } 170 | }) 171 | 172 | //以下为同步方法 173 | //let base64 = wx.getFileSystemManager().readFileSync(res.tempFilePaths[0], 'base64') 174 | //console.log(base64) 175 | 176 | 177 | 178 | 179 | 180 | }, 181 | fail: res => { 182 | console.log(res.errMsg) 183 | } 184 | }) 185 | }, 100)) 186 | }, //留一定的时间绘制canvas 187 | fail: res => { 188 | console.log(res.errMsg) 189 | } 190 | }) 191 | 192 | 193 | 194 | } 195 | }); 196 | }, 197 | banquan: function () { 198 | wx.navigateToMiniProgram({ 199 | appId: 'wx9588ff2d3063ee31', 200 | path: '', 201 | envVersion: 'release', 202 | success(res) { 203 | // 打开成功 204 | } 205 | }) 206 | }, 207 | onLoad: function(n) {}, 208 | onReady: function() {}, 209 | onShow: function() {}, 210 | onHide: function() {}, 211 | onUnload: function() {}, 212 | onPullDownRefresh: function() {}, 213 | onReachBottom: function() {}, 214 | onShareAppMessage: function() {} 215 | }); 216 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------