1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php namespace Msg\Lib\Method;
- use Dever;
- class Wechat_applet
- {
- private $config;
- # 初始化
- public function init($template_id, $config_id, $account, $project = 'api')
- {
- if (empty($param['openid'])) {
- Dever::error('openid不存在');
- }
- $msg = 'msg';
- if ($project != 'api') {
- $msg = $project;
- }
- $this->config = Dever::db('account_wechat', $msg)->find(['account_id' => $config_id, 'template_id' => $template_id]);
- if (!$this->config) {
- Dever::error('小程序配置不存在');
- }
- $this->config['project'] = $project;
- $this->config['account'] = $param['openid'];
- return $this->config['account'];
- }
- # 发送
- public function send($api, $content, $param)
- {
- if (!$this->config) {
- Dever::error('小程序配置不存在');
- }
- $data = [];
- foreach ($param as $k => $v) {
- $data[$k]['value'] = $v;
- }
- $send['touser'] = $this->config['account'];
- $send['template_id'] = $this->config['code'];
- $send['page'] = $param['page'] ?? '';
- $send['data'] = $data;
- $send['log'] = true;
- $result = Dever::load('account', 'api')->run($api, 'applet_send', $send, 1, 'run', $this->config['project']);
- return Dever::json_encode($result);
- }
- }
|