PHP code example of quansitech / send-msg
1. Go to this page and download the library: Download quansitech/send-msg library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
quansitech / send-msg example snippets
'SEND_MSG_SMS_GATEWAY'=> [
//云片
'yunpian'=>[
'api_key'=>'27f03185cb9b6e1a4f274b*******',
'sign_text'=>'【云片签名】'
],
],
class MsgTemplateParse extends BaseMsgTemplateParse {
static protected $_var_func = array(
'项目名称' => 'parseProjectName',
);
static public function parseProjectName($args){
$project_id = $args['project_id'];
return D('Project')->where(['id'=>$project_id])->getField('title');
}
}
//MsgTemplateParse为上一步所定义的类
$builder=\QsSendMsg\SendMsgJobBuilder::getInstance()->setTemplateParser(MsgTemplateParse::class);
/** @var $builder \QsSendMsg\SendMsgJobBuilder */
$builder->setMsgTpl('test_msg',['project_id'=>1])
->addSmsMsgJob('13100000000','发送短信')
->addWxMsgJob('[openid]','[消息模板id]','[消息内容对象]','[跳转的url]','发送微信消息','[内容填充字段(默认为"first")]');
$msgData = [
'first' => ['value' => 'test', 'color' => '#173177'],
'keyword1' => ['value' => 'keyword1', 'color' => '#173177'],
'keyword2' => ['value' => 'keyword2', 'color' => '#173177'],
'remark' => ['value' => 'remark', 'color' => '#173177'],
];
/** @var $builder \QsSendMsg\SendMsgJobBuilder 第4步的$builder*/
$builder->dispatchAll();
/** @var $builder \QsSendMsg\SendMsgJobBuilder 第4步的$builder*/
$builder->dispatch();
$job = new \QsSendMsg\Job\SendWxMsgJob();
$r=$job->send([
'open_id'=>'微信openid',
'template_id'=>'微信模板消息ID',
'url'=>'跳转地址',
'data'=>'消息内容'
]);
$job = new \QsSendMsg\Job\SendSmsMsgJob();
$r=$job->send([
'mobile'=>'手机号',
'content'=>'短信内容',
//...其它参数
]);
'SEND_MSG_SMS_GATEWAY'=> [
//云片
'yunpian'=>[
'api_key'=>'27f03185cb9b6e1a4f274b*******',
'sign_text'=>'【云片签名】'
],
],
shell script
php resque start --queue=wx #微信消息
php resque start --queue=sms #短信消息