You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace app\base\logic;
use EasyWeChat\Factory;
class Wechat extends Base
{
protected $easyWechatConfig; //easywechat微信配置文件
protected $wechatConfig; //公众平台配置
public function __construct($data = [])
{
parent::__construct($data);
$weixin_param = get_weixin_config();
$this->wechatConfig = $weixin_param;
$this->easyWechatConfig = [
'app_id' => $weixin_param['app_id'],
'secret' => $weixin_param['app_secret'],
'token' => $weixin_param['token'],
'response_type' => 'array',
//日志 配置
'log' => [
'default' => 'dev', // 默认使用的 channel生产环境可以改为下面的 prod
'channels' => [
// 测试环境
'dev' => [
'driver' => 'daily',
'path' => root_path() . 'runtime/easywechat/easywechat.log',
'level' => 'debug',
'days' => 1
]
],
],
//OAuth 配置
'oauth' => [
'scopes' => ['snsapi_userinfo'],
// 'callback' => '/examples/oauth_callback.php',
],
];
}
/**
* 发布菜单
* @param array $classify 要发布的菜单
* @date 2020-10-21
*/
public function classifyPublish($classify)
{
$app = Factory::officialAccount($this->easyWechatConfig);
return $app->menu->create($classify);
}
/**
* 删除菜单
* @date 2020-10-21
*/
public function classifyDel()
{
$app = Factory::officialAccount($this->easyWechatConfig);
return $app->menu->delete();
}
/**
* 素材管理--获取永久素材
* @param string $media_id 微信返回媒体标识
* @param string $file_formats 文件格式 一般有jpg,gif,png,jpeg,amr,mp3,mp4
* @param string $material_type 媒体文件类型 image--图片 voice--语音2M video--视频 thumb--缩略图
* @date 2020-10-10
*/
function getPermanentMaterial($media_id)
{
$app = Factory::officialAccount($this->easyWechatConfig);
$resource = $app->material->get($media_id);
return $resource;
}
}