当前位置: 首页 > news >正文

PHP:连接钉钉接口-钉钉回调事件,本地测试数据

前置数据参考 

数据说明:参见官方文档回调事件消息体加解密 - 钉钉开放平台 (dingtalk.com)

URL后面带的参数:

signature=5a65ceeef9aab2d149439f82dc191dd6c5cbe2c0&timestamp=1445827045067&nonce=nEXhMP4r

Post参数:

{         "encrypt":"1a3NBxmCFwkCJvfoQ7WhJHB+iX3qHPsc9JbaDznE1i03peOk1LaOQoRz3+nlyGNhwmwJ3vDMG+OzrHMeiZI7gTRWVdUBmfxjZ8Ej23JVYa9VrYeJ5as7XM/ZpulX8NEQis44w53h1qAgnC3PRzM7Zc/D6Ibr0rgUathB6zRHP8PYrfgnNOS9PhSBdHlegK+AGGanfwjXuQ9+0pZcy0w9lQ==" }

Env.TOKEN:123456

Env.ENCODING_AES_KEY:4g5j64qlyl3zvetqxz5jiocdr586fn2zvjpa8zls3ij

Env.KEY:suite4xxxxxxxxxxxxxxx

代码(info_return.php)

<?php
define( 'TOKEN', '123456' );
define( 'ENCODING_AES_KEY', '4g5j64qlyl3zvetqxz5jiocdr586fn2zvjpa8zls3ij' );
define( 'SUITE_KEY', 'suite4xxxxxxxxxxxxxxx' );
// 包含 DingtalkCrypt 类
require_once 'DingtalkCrypt.php';$signature = $_GET[ 'signature' ];
$timeStamp = $_GET[ 'timestamp' ];
$nonce = $_GET[ 'nonce' ];
// $postdata = file_get_contents( 'php://input' );
// $postList = json_decode( $postdata, true );
// $encrypt = $postList[ 'encrypt' ];
$encrypt = '1a3NBxmCFwkCJvfoQ7WhJHB+iX3qHPsc9JbaDznE1i03peOk1LaOQoRz3+nlyGNhwmwJ3vDMG+OzrHMeiZI7gTRWVdUBmfxjZ8Ej23JVYa9VrYeJ5as7XM/ZpulX8NEQis44w53h1qAgnC3PRzM7Zc/D6Ibr0rgUathB6zRHP8PYrfgnNOS9PhSBdHlegK+AGGanfwjXuQ9+0pZcy0w9lQ==';
$crypt = new DingtalkCrypt( TOKEN, ENCODING_AES_KEY, SUITE_KEY );$msg = '';
$errCode = $crypt->DecryptMsg( $signature, $timeStamp, $nonce, $encrypt, $msg );if ( $errCode != 0 ) {echo ( json_encode( $_GET ) . '  ERR:' . $errCode );/*** 创建套件时检测回调地址有效性,使用CREATE_SUITE_KEY作为SuiteKey*/// $crypt = new DingtalkCrypt( TOKEN, ENCODING_AES_KEY, CREATE_SUITE_KEY );// $errCode = $crypt->DecryptMsg( $signature, $timeStamp, $nonce, $encrypt, $msg );if ( $errCode == 0 ) {// echo( 'DECRYPT CREATE SUITE MSG SUCCESS ' . json_encode( $_GET ) . '  ' . $msg );$eventMsg = json_decode( $msg );$eventType = $eventMsg->EventType;if ( 'check_create_suite_url' === $eventType ) {$random = $eventMsg->Random;$testSuiteKey = $eventMsg->TestSuiteKey;$encryptMsg = '';$errCode = $crypt->EncryptMsg( $random, $timeStamp, $nonce, $encryptMsg );if ( $errCode == 0 ) {echo ( 'CREATE SUITE URL RESPONSE: ' . $encryptMsg );echo $encryptMsg;} else {echo ( 'CREATE SUITE URL RESPONSE ERR: ' . $errCode );}} else {// should never happened}} else {echo ( json_encode( $_GET ) . 'CREATE SUITE ERR:' . $errCode );}return;
} else {/*** 套件创建成功后的回调推送*/// echo( 'DECRYPT MSG SUCCESS ' . json_encode( $_GET ) . '  ' . $msg );$eventMsg = json_decode( $msg );$eventType = $eventMsg->EventType;/*** 套件ticket*/if ( 'suite_ticket' === $eventType ) {Cache::setSuiteTicket( $eventMsg->SuiteTicket );}/*** 临时授权码*/else if ( 'tmp_auth_code' === $eventType ) {$tmpAuthCode = $eventMsg->AuthCode;Activate::autoActivateSuite( $tmpAuthCode );}/*** 授权变更事件*//*user_add_org : 通讯录用户增加user_modify_org : 通讯录用户更改user_leave_org : 通讯录用户离职org_admin_add :通讯录用户被设为管理员org_admin_remove :通讯录用户被取消设置管理员org_dept_create : 通讯录企业部门创建org_dept_modify : 通讯录企业部门修改org_dept_remove : 通讯录企业部门删除org_remove : 企业被解散*/ else if ( 'user_add_org' === $eventType ) {echo ( json_encode( $_GET ) . '  ERR:user_add_org' );// handle auth change event} else if ( 'user_modify_org' === $eventType ) {echo ( json_encode( $_GET ) . '  ERR:user_modify_org' );// handle auth change event} else if ( 'user_leave_org' === $eventType ) {echo ( json_encode( $_GET ) . '  ERR:user_leave_org' );// handle auth change event}/*** 应用被解除授权的时候,需要删除相应企业的存储信息*/else if ( 'suite_relieve' === $eventType ) {$corpid = $eventMsg->AuthCorpId;ISVService::removeCorpInfo( $corpid );// handle auth change event} else if ( 'change_auth' === $eventType ) {// handle auth change event}/*** 回调地址更新*/else if ( 'check_update_suite_url' === $eventType ) {$random = $eventMsg->Random;$testSuiteKey = $eventMsg->TestSuiteKey;$encryptMsg = '';$errCode = $crypt->EncryptMsg( $random, $timeStamp, $nonce, $encryptMsg );if ( $errCode == 0 ) {// echo( 'UPDATE SUITE URL RESPONSE: ' . $encryptMsg );echo $encryptMsg;return;} else {// echo( 'UPDATE SUITE URL RESPONSE ERR: ' . $errCode );}} else {// should never happen}$res = 'success';$encryptMsg = '';$errCode = $crypt->EncryptMsg( $res, $timeStamp, $nonce, $encryptMsg );if ( $errCode == 0 ) {echo $encryptMsg;// echo( 'RESPONSE: ' . $encryptMsg );} else {// echo( 'RESPONSE ERR: ' . $errCode );}
}

http://www.lryc.cn/news/413288.html

相关文章:

  • 【C++标准模版库】vector的介绍及使用
  • 数说故事|引爆社媒的森贝儿IP,品牌如何实现流量变现?
  • 使用openpyxl库对Excel条件格式的深度探索
  • 原生javascript中的ajax通信技术
  • SpringBoot Vue用自签名证书SSL配置https,http转发到https(整理文章)
  • 嵌入式人工智能(41-基于树莓派4B的串口蓝牙模块AT09-cc2541)
  • C++ 动态规划
  • 回溯问题总结
  • GraphRAG如何使用ollama提供的llm model 和Embedding model服务构建本地知识库
  • .net # 检查 带有pdf xss
  • 【React】探讨className的正确使用方式
  • 打靶记录5——靶机hard_socnet2
  • 独立站+TikTok达人:自主营销与创意内容的完美结合
  • 【启明智显分享】适用于多功能养生壶、茶吧机的2.8寸触摸彩屏解决方案
  • WAF绕过技术(PKAV团队)
  • 『 Linux 』POSIX 信号量与基于环形队列的生产者消费者模型
  • python中的字符串方法
  • python实现consul的服务注册与注销
  • 校园选课助手【2】-重要的登录模块
  • 4章2节:从排序到分组和筛选,通过 R 的 dplyr 扩展包来操作
  • C语言实现 -- 单链表
  • WSL和Windows建立TCP通信协议
  • Android Gradle开发与应用(一):Gradle基础
  • Linux多线程服务器编程-1-线程安全的对象生命期管理
  • Couchbase 技术详解
  • PTE-信息收集
  • 委外订单执行明细表增加二开字段
  • “数字孪生+大模型“:打造设施农业全场景数字化运营新范式
  • zeppline 连接flink 1.17报错
  • 【机器视觉】【目标检测】【面试】独家问题总结表格