# 第六课微擎高级操作
- token获取
```
<pre class="calibre14">```
$token <span class="token">=</span> WeAccount<span class="token2">:</span><span class="token2">:</span><span class="token1">token</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
```
```
- - 加载类
```
<pre class="calibre14">```
$weixin <span class="token">=</span> weixinpay<span class="token2">:</span><span class="token2">:</span><span class="token1">create</span><span class="token2">(</span><span class="token4">'wechat'</span><span class="token2">)</span><span class="token2">;</span>
$userinfo <span class="token">=</span> $weixin<span class="token">-</span><span class="token">></span><span class="token1">getOauthInfo</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
```
```
```
<pre class="calibre14">```
<span class="token1">load</span><span class="token2">(</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">model</span><span class="token2">(</span><span class="token4">'mc'</span><span class="token2">)</span><span class="token2">;</span>
$wechat <span class="token">=</span> $_W<span class="token2">[</span><span class="token4">'account'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'setting'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'payment'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'wechat'</span><span class="token2">]</span><span class="token2">;</span><span class="token6">//支付设置</span>
$wechat <span class="token">=</span><span class="token2">(</span><span class="token">!</span><span class="token1">empty</span><span class="token2">(</span>$wechat<span class="token2">[</span><span class="token4">'borrow'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">)</span><span class="token">?</span> <span class="token1">uni_setting</span><span class="token2">(</span>$wechat<span class="token2">[</span><span class="token4">'borrow'</span><span class="token2">]</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'payment'</span><span class="token2">)</span><span class="token2">)</span><span class="token2">[</span><span class="token4">'payment'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'wechat'</span><span class="token2">]</span><span class="token2">:</span>$wechat<span class="token2">;</span>
```
```
长网址转换短网址
```
<pre class="calibre14">```
<span class="token1">load</span><span class="token2">(</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">classs</span><span class="token2">(</span><span class="token4">'weixin.account'</span><span class="token2">)</span><span class="token2">;</span>
$acc <span class="token">=</span> WeiXinAccount<span class="token2">:</span><span class="token2">:</span><span class="token1">create</span><span class="token2">(</span>$_W<span class="token2">[</span><span class="token4">'acid'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span>
$url <span class="token">=</span> $acc<span class="token">-</span><span class="token">></span><span class="token1">long2short</span><span class="token2">(</span><span class="token4">"http://www.baidu.com"</span><span class="token2">)</span><span class="token2">[</span><span class="token4">'short_url'</span><span class="token2">]</span><span class="token2">;</span>
```
```
文件上传,返回media\_id
```
<pre class="calibre14">```
<span class="token5">if</span><span class="token2">(</span><span class="token1">is_file</span><span class="token2">(</span>ATTACHMENT_ROOT<span class="token2">.</span><span class="token4">"/1.jpg"</span><span class="token2">)</span><span class="token2">)</span><span class="token2">{</span>
$path <span class="token">=</span><span class="token4">"1.jpg"</span><span class="token2">;</span>
<span class="token2">}</span><span class="token5">else</span><span class="token2">{</span>
<span class="token1">load</span><span class="token2">(</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">func</span><span class="token2">(</span><span class="token4">'file'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">file_move</span><span class="token2">(</span>MODULE_ROOT<span class="token2">.</span><span class="token4">"/1.jpg"</span><span class="token2">,</span>ATTACHMENT_ROOT<span class="token2">.</span><span class="token4">"/1.jpg"</span><span class="token2">)</span><span class="token2">;</span>
$path <span class="token">=</span><span class="token4">"1.jpg"</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token1">load</span><span class="token2">(</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">classs</span><span class="token2">(</span><span class="token4">'weixin.account'</span><span class="token2">)</span><span class="token2">;</span>
$acc <span class="token">=</span> WeiXinAccount<span class="token2">:</span><span class="token2">:</span><span class="token1">create</span><span class="token2">(</span>$_W<span class="token2">[</span><span class="token4">'acid'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span>
$media <span class="token">=</span> $acc<span class="token">-</span><span class="token">></span><span class="token1">uploadMedia</span><span class="token2">(</span>$path<span class="token2">)</span><span class="token2">;</span>
<span class="token1">dump</span><span class="token2">(</span>$media<span class="token2">)</span><span class="token2">;</span>
Array
<span class="token2">(</span>
<span class="token2">[</span>type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> image
<span class="token2">[</span>media_id<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">4</span>IftJVo5o<span class="token">-</span>qS2hm0Q0ID<span class="token">-</span>_m5VARGL2eqKsgT1ih7v63SA8pULoqplVzIEU4hdt7y
<span class="token2">[</span>created_at<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1515481289</span>
<span class="token2">)</span>
```
```
下载文件
```
<pre class="calibre14">```
<span class="token1">load</span><span class="token2">(</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">classs</span><span class="token2">(</span><span class="token4">'weixin.account'</span><span class="token2">)</span><span class="token2">;</span>
$acc <span class="token">=</span> WeiXinAccount<span class="token2">:</span><span class="token2">:</span><span class="token1">create</span><span class="token2">(</span>$_W<span class="token2">[</span><span class="token4">'acid'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span>
$arr <span class="token">=</span> <span class="token2">[</span><span class="token4">'media_id'</span><span class="token">=</span><span class="token">></span><span class="token4">"4IftJVo5o-qS2hm0Q0ID-_m5VARGL2eqKsgT1ih7v63SA8pULoqplVzIEU4hdt7y"</span><span class="token2">,</span><span class="token4">'type'</span><span class="token">=</span><span class="token">></span><span class="token4">"image"</span><span class="token2">]</span><span class="token2">;</span>
$media <span class="token">=</span> $acc<span class="token">-</span><span class="token">></span><span class="token1">downloadMedia</span><span class="token2">(</span>$arr<span class="token2">)</span><span class="token2">;</span>
<span class="token6">//images/5/2018/01/4IftJVo5o-qS2hm0Q0ID-_m5VARGL2eqKsgT1ih7v63SA8pULoqplVzIEU4hdt7y.jpg 返回路径</span>
<span class="token">~</span><span class="token">~</span><span class="token">~</span>
读取与写入实实配置
```
```
$config = pdo\_getcolumn('uni\_account\_modules',\[
'module' => 模块名,
'uniacid' => $\_W\['uniacid'\]
\],'settings');
$config = iunserializer($config);
pdo\_update('uni\_account\_modules',\[
'settings' =>iserializer($config),
\], \[
'module' =>模块名,
'uniacid' => $\_W\['uniacid'\]
\]);
```
<pre class="calibre16">```
发送客服消息
<span class="token">~</span><span class="token">~</span><span class="token">~</span>
$info <span class="token">=</span> <span class="token4">"我是客服消息:\n 欢迎使用"</span><span class="token2">;</span>
$openid <span class="token">=</span> <span class="token4">"ocUeXwINHvRqWPSldYZVO4dA_CzI"</span><span class="token2">;</span>
$message <span class="token">=</span> <span class="token2">[</span>
<span class="token4">'msgtype'</span><span class="token">=</span><span class="token">></span><span class="token4">'text'</span><span class="token2">,</span>
<span class="token4">'text'</span><span class="token">=</span><span class="token">></span><span class="token2">[</span><span class="token4">'content'</span><span class="token">=</span><span class="token">></span><span class="token1">urlencode</span><span class="token2">(</span>$info<span class="token2">)</span><span class="token2">]</span><span class="token2">,</span>
<span class="token4">'touser'</span><span class="token">=</span><span class="token">></span>$openid
<span class="token2">]</span><span class="token2">;</span>
$acc <span class="token">=</span> WeAccount<span class="token2">:</span><span class="token2">:</span><span class="token1">create</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
$status <span class="token">=</span> $acc<span class="token">-</span><span class="token">></span><span class="token1">sendCustomNotice</span><span class="token2">(</span>$message<span class="token2">)</span><span class="token2">;</span>
<span class="token5">if</span> <span class="token2">(</span><span class="token1">is_error</span><span class="token2">(</span>$status<span class="token2">)</span><span class="token2">)</span> <span class="token2">{</span>
<span class="token1">message</span><span class="token2">(</span><span class="token4">'发送失败,原因为'</span> <span class="token2">.</span> $status<span class="token2">[</span><span class="token4">'message'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
$message <span class="token">=</span> <span class="token2">[</span>
<span class="token4">'touser'</span> <span class="token">=</span><span class="token">></span> $openid<span class="token2">,</span>
<span class="token4">'msgtype'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'image'</span><span class="token2">,</span>
<span class="token4">'image'</span> <span class="token">=</span><span class="token">></span><span class="token2">[</span><span class="token4">'media_id'</span><span class="token">=</span><span class="token">></span> <span class="token4">'MEDIA_ID'</span><span class="token2">]</span><span class="token6">//微信素材media_id,微擎中微信上传组件可以得到此值</span>
<span class="token2">]</span><span class="token2">;</span>
$message <span class="token">=</span> <span class="token2">[</span>
<span class="token4">'touser'</span> <span class="token">=</span><span class="token">></span> $openid<span class="token2">,</span>
<span class="token4">'msgtype'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'music'</span><span class="token2">,</span>
<span class="token4">'music'</span> <span class="token">=</span><span class="token">></span> <span class="token2">[</span>
<span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'标题'</span><span class="token2">,</span>
<span class="token4">'description'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'描述'</span>
<span class="token4">'musicurl'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'音乐文件URL'</span><span class="token2">,</span>
<span class="token4">'hqmusicurl'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'高清音乐文件URL'</span><span class="token2">,</span>
<span class="token4">'thumb_media_id'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'MEDIA_ID'</span><span class="token2">,</span>
<span class="token2">]</span>
<span class="token2">]</span><span class="token2">;</span>
$message <span class="token">=</span> <span class="token2">[</span>
<span class="token4">'touser'</span> <span class="token">=</span><span class="token">></span> $openid<span class="token2">,</span>
<span class="token4">'msgtype'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'news'</span><span class="token2">,</span>
<span class="token4">'news'</span> <span class="token">=</span><span class="token">></span><span class="token2">[</span>
<span class="token2">[</span>
<span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'标题'</span><span class="token2">,</span>
<span class="token4">'description'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'描述'</span><span class="token2">,</span>
<span class="token4">'url'</span> <span class="token2">:</span> <span class="token4">'链接'</span><span class="token2">,</span>
<span class="token4">'picurl'</span> <span class="token2">:</span> <span class="token4">'封面图片地址'</span>
<span class="token2">]</span><span class="token2">,</span>
<span class="token2">[</span>
<span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'标题1'</span><span class="token2">,</span>
<span class="token4">'description'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'描述1'</span><span class="token2">,</span>
<span class="token4">'url'</span> <span class="token2">:</span> <span class="token4">'链接'</span><span class="token2">,</span>
<span class="token4">'picurl'</span> <span class="token2">:</span> <span class="token4">'封面图片地址'</span>
<span class="token2">]</span><span class="token2">,</span>
<span class="token2">]</span>
<span class="token2">]</span><span class="token2">;</span>
$message <span class="token">=</span> <span class="token2">[</span>
<span class="token4">'touser'</span> <span class="token">=</span><span class="token">></span> $openid<span class="token2">,</span>
<span class="token4">'msgtype'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'wxcard'</span><span class="token2">,</span>
<span class="token4">'wxcard'</span> <span class="token">=</span><span class="token">></span> <span class="token2">[</span><span class="token4">'card_id'</span><span class="token">=</span><span class="token">></span> <span class="token4">'CARD_ID'</span><span class="token2">]</span>
<span class="token2">]</span><span class="token2">;</span>
<span class="token">~</span><span class="token">~</span><span class="token">~</span>
发送模板消息
<span class="token">~</span><span class="token">~</span><span class="token">~</span>
$tpl_id <span class="token">=</span> <span class="token4">"QDDIbJpHEann2VeN12r6GXf0OiTJMky8uL4FAK2zAp8"</span><span class="token2">;</span>
$openid <span class="token">=</span> <span class="token4">"ocUeXwINHvRqWPSldYZVO4dA_CzI"</span><span class="token2">;</span>
$url <span class="token">=</span> <span class="token4">""</span><span class="token2">;</span>
$arr <span class="token">=</span><span class="token2">[</span><span class="token2">]</span><span class="token2">;</span>
$sendarr <span class="token">=</span><span class="token2">[</span><span class="token4">'测试通知标题'</span><span class="token2">,</span><span class="token4">'西安大学'</span><span class="token2">,</span><span class="token4">'管理员'</span><span class="token2">,</span><span class="token4">'2018-4-28'</span><span class="token2">,</span><span class="token4">'商城决定展示关闭'</span><span class="token2">,</span><span class="token4">'点击查看详情'</span><span class="token2">]</span><span class="token2">;</span>
$tpl <span class="token">=</span> '<span class="token2">{</span><span class="token2">{</span>first<span class="token2">.</span>DATA<span class="token2">}</span><span class="token2">}</span>
学校:<span class="token2">{</span><span class="token2">{</span>keyword1<span class="token2">.</span>DATA<span class="token2">}</span><span class="token2">}</span>
通知人:<span class="token2">{</span><span class="token2">{</span>keyword2<span class="token2">.</span>DATA<span class="token2">}</span><span class="token2">}</span>
时间:<span class="token2">{</span><span class="token2">{</span>keyword3<span class="token2">.</span>DATA<span class="token2">}</span><span class="token2">}</span>
通知内容:<span class="token2">{</span><span class="token2">{</span>keyword4<span class="token2">.</span>DATA<span class="token2">}</span><span class="token2">}</span>'<span class="token2">;</span>
<span class="token1">preg_match_all</span><span class="token2">(</span><span class="token4">'/{{(.*).DATA}}/'</span><span class="token2">,</span>$tpl<span class="token2">,</span>$rs<span class="token2">)</span><span class="token2">;</span>
<span class="token1">foreach</span><span class="token2">(</span>$rs<span class="token2">[</span><span class="token3">1</span><span class="token2">]</span> as $k<span class="token">=</span><span class="token">></span>$v<span class="token2">)</span><span class="token2">{</span>
$arr<span class="token2">[</span>$v<span class="token2">]</span> <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span>
<span class="token4">'value'</span><span class="token">=</span><span class="token">></span>$sendarr<span class="token2">[</span>$k<span class="token2">]</span>
<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
$arr<span class="token2">[</span><span class="token4">'first'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'color'</span><span class="token2">]</span><span class="token">=</span><span class="token4">'#04be02'</span><span class="token2">;</span>
$arr<span class="token2">[</span><span class="token4">'remark'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'color'</span><span class="token2">]</span><span class="token">=</span><span class="token4">'#18b4ed'</span><span class="token2">;</span>
$acc <span class="token">=</span> WeAccount<span class="token2">:</span><span class="token2">:</span><span class="token1">create</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
$status <span class="token">=</span> $acc<span class="token">-</span><span class="token">></span><span class="token1">sendTplNotice</span><span class="token2">(</span>$openid<span class="token2">,</span>$tpl_id<span class="token2">,</span> $arr<span class="token2">,</span> $url<span class="token2">)</span><span class="token2">;</span> <span class="token6">//1表示发送成功 </span>
<span class="token">~</span><span class="token">~</span><span class="token">~</span>
获取用户信息oauth
<span class="token">~</span><span class="token">~</span><span class="token">~</span>
<span class="token1">load</span><span class="token2">(</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">classs</span><span class="token2">(</span><span class="token4">'weixin.account'</span><span class="token2">)</span><span class="token2">;</span>
$acc <span class="token">=</span> WeiXinAccount<span class="token2">:</span><span class="token2">:</span><span class="token1">create</span><span class="token2">(</span>$_W<span class="token2">[</span><span class="token4">'acid'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span>
$userinfo <span class="token">=</span>$acc<span class="token">-</span><span class="token">></span><span class="token1">fansQueryInfo</span><span class="token2">(</span>$openid<span class="token2">)</span><span class="token2">;</span>
<span class="token">~</span><span class="token">~</span><span class="token">~</span>
```
```
- 简介
- 第一章 数据库
- Mysql/mariadb
- 函数
- 基础
- 增删改索引
- 标准查询
- 高级查询
- TIDB集群mysql解决方案
- Redis
- 语言基础
- 5种数据类型
- 其他类型
- Sqlite
- 语言基础
- 常用查询
- 第二章 PHP
- 语言基础
- 第一课 流程控制和运算
- 第二课 数组
- 第三课 日期时间
- 第四课 常用函数
- 第五课 字符串
- 第六课 文件操作
- 第七课 面向对象
- 第八课 正则表达式
- 第九课 图片处理生成
- 第十课 curl/memche
- 第十一课 mysql和pdo
- 第十三课 cookie和session
- 第十四课 xml操作
- 第十五课 php5.3+新特性
- 第十六课 php7+
- 第十七课 密码安全
- 废弃函数
- php命令行
- redis应用
- 算法
- 排序算法
- 基础算法
- 无限级分类
- 自定义函数Fn
- 查找算法
- 自定义函数数据函数fn
- laravel
- 路由
- 常用语句
- 数据库
- dingo/api
- Yii2
- 控制器
- 常用类
- 数据库
- redis
- thinkphp6
- TP6文档
- TP6插件
- dedecms
- 织梦标签大全
- 数据库操作
- 内置函数和定义函数
- 织梦核心改动
- 织梦插件/底层标签开发
- PHP相关工具
- composer
- php开发环境phpenv
- Phpstorm使用
- windows编译php扩展
- PHP开源库
- 开源项目管理禅道
- sns_auth
- php-casbin权限控制
- php-jwt
- 微信SDKeasywechat
- querylist采集库
- workerman
- Box/Spout处理excel和csv
- dll扩展
- redis/memche/xdebug
- redis
- Lua
- php_xlswriter
- event
- swoole
- 常用代码库
- 微擎框架
- 第一课全局变量
- 第二课常用函数
- 第三课自定义微擎独有函数
- 第四课数据库操作
- 第五课微信端回复
- 第六课微擎高级操作
- 第八课global函数列表
- mainfest.xml详解
- js方法
- 人人商城
- 第一课model解读
- 第二课常用语句解读
- 第三课常用js解读
- 第四课附录常见问题
- 第五课附录处理报表|支付
- 常用JSON状态码
- 第三章 JavaScript
- js基础
- 浏览器对象
- 语言基础
- html5接口
- ES6新语法
- vue
- 基础语法
- 京东vueUI组件
- uniapp
- 组件开发规范
- nodejs
- 基础知识
- 安装node
- nvm不同版本node切换
- js常用标准库
- zepto/jquery
- weui
- js图标库
- elementUI
- validator表单验证
- layer弹出层
- requirejs
- wow动画
- 动画animate
- swiper4
- 百度编辑器
- flyio/axios/qs
- jquery.form
- bootstrap3
- clipboard复制
- slideout侧滑
- imagehover.css图片悬停动画
- webpack打包
- Bulma UI框架
- store 客户端存储
- lottie动画创建库
- sweetalert
- js自定义函数
- 常见JSSDK
- 微信公众号JSSDK
- 腾讯地图jssdk
- 微信小程序
- 第四章 编程语言
- markdown语言
- Dart语言
- Dart语言基础
- Flutter框架
- Lua语言
- 字符串,数组,表
- 自定义方法
- go语言
- 第1.1语言基本语法
- 第1.2流程控制
- 第1.3函数
- 第1.4结构体
- 第1.5接口
- 第1.6包
- go语言框架Gin
- CSS3语言
- CSS与CSS3
- 选择符
- 属性
- css3
- loading动画
- HTML5语言
- less
- sass
- C#
- 基础知识
- 函数
- 第五章 开发工具
- git
- nginx/apache服务器
- Linux常用操作
- crontab定时任务
- 注册表与cmd
- 阿里云ECS
- frp穿透和ssl续期
- 宝塔安装
- 树莓派
- 浏览器模拟
- 火狐/chrome常用插件
- WSL安装使用
- mac brew和终端命令
- win10相关