浙政钉发送消息文档:https://openplatform-portal.d...

1:引入sdk:https://openplatform-portal.d...

2:发送消息实现(这里我只实现文本消息,具体其他形式消息,可查看文档实现)

//接收消息
$msg = [
    'msgtype' => 'text',
    'text' => [
        'content' => '测试消息'
    ]
];
try {
    $executableClient = new ExecutableClient();
    //Saas环境域名为:https://openplatform.dg-work.cn,浙政钉环境域名为:https://openplatform-pro.ding.zj.gov.cn
    $executableClient->setDomain('域名');
    $executableClient->setAccessKey('应用App Key');
    $executableClient->setSecretKey('应用App Secret');
    $executableClient->setApiName('/chat/sendMsg');

    $executableClient->addParameter('msg', json_encode($msg));//消息体(参考下文示例消息格式)
    $executableClient->addParameter('senderId', '发送者用户id');
    $executableClient->addParameter('receiverId', '单聊接受者用户id(chatType为1时必填)');
    $executableClient->addParameter('tenantId', '租户id');
    $executableClient->addParameter('chatType', 1);//发起的会话类型(1单聊、2群聊)
    $result = $executableClient->epaasCurlGet(3);
} catch (\Exception $e) {
    $msg = "getFilterWords|err, code: ". $e->getCode() . "|message: ". $e->getMessage();
    Yii::error($msg);
    return $msg;
}
if (isset($result['success']) && $result['success'] == true) {
    return true;//发送成功
}
return false;//发送失败

如上我们就可以实现消息通知功能了


huaweichenai
679 声望114 粉丝