6

CRMEB 多商户二开新增一个模板消息

 2 years ago
source link: https://segmentfault.com/a/1190000040719442
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

CRMEB 多商户二开新增一个模板消息

发布于 9 月 22 日

使用过程中,可能会需要增加一些微信的模板消息来实现功能,这里就具体的将整个流程演示一遍。

首先登录个人的微信后台:https://mp.weixin.qq.com/,然后申请一个自己需要的消息模板,我这里以《访客接待消息通知》为例,下图是我申请好的截图。

将刚才申请的模板信息填写到平台后台的模板管理中去,如下图

代码实现部分,以下 … … 是省略了源代码中的未修改的代码部分。
修改配置文件,config/template.php 文件,因为我们增加的是微信公众号消息,所以在wechat数组下增加一行,这里的键可以自定义,值就是刚才申请的模板编号,如图:

增加模板消息的内容设定,所有模板消息或者订阅消息的内容都在crmeb/services/WechatTemplateMessageService.php 文件中实现的;
修改入口文件,因为我们这个模板需要传入额外的参数,但是原来的方法中并没有这个,所以我们增加一个 $data[‘data’] ?? [] 参数的传入。
public function sendTemplate(array $data)
{

$res = $this->templateMessage($data['tempCode'],$data['id'], $data['data'] ?? []);

增加内容设定
public function templateMessage(string $tempCode, $id, $params = [])
{

$bill_make = app()->make(UserBillRepository::class);

    $order_make = app()->make(StoreOrderRepository::class);

    $refund_make = app()->make(StoreRefundOrderRepository::class);

    $order_status_make = app()->make(StoreOrderStatusRepository::class);



switch ($tempCode) {

case'SERVER_NOTICE':

    /*
    {{first.DATA}}
    访客姓名:{{keyword1.DATA}}
    联系方式:{{keyword2.DATA}}
    项目名称:{{keyword3.DATA}}
    {{remark.DATA}}
     */
    $mer = app()->make(MerchantRepository::class)->get($params['mer_id']);
    $user = app()->make(UserRepository::class)->get($id);
    $data[] = [
        'tempCode' => 'SERVER_NOTICE',
        'uid' => $id,
        'data' => [
            'first' => '亲,您有新的消息请注意查看~',
            'keyword1' => $user['nickname'],
            'keyword2' => $mer['mer_name'],
            'keyword3' => $params['keyword3'],
            'remark' => ''
        ],
        'link' => '',
        'color' => null
    ];
    break;
default:
    return false;
    break;

}
return $data;

上面就将模板消息的内容也设定好了,现在就去需要使用的地方调用就好了,我们找到客服消息的监听文件,然后替换之前的发短信提醒的地方,如下图:

这样我们就完成了整个流程的开发了。

如果你觉得这篇文章对你有点用的话,麻烦请给我们的开源项目点点star: http://github.crmeb.net/u/defu不胜感激 !


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK