钉钉事件订阅加解密库DingCallbackCrypto(thinkphp6)学习

目的:开通事件订阅功能
环境
php 7.2 htinkphp6
DingCallbackCrypto参数
企业内部开发
H5微应用

<?php
/**
 * PHP7.1及其之上版本的回调加解密类库
 * 该版本依赖openssl_encrypt方法加解密,注意版本依赖 (PHP 5 >= 5.3.0, PHP 7)
 */
class DingCallbackCrypto
{
    
    
    private $m_token;
    private $m_encodingAesKey;
    private $m_corpId;
    //注意这里修改为构造函数
    function __construct($token, $encodingAesKey, $ownerKey)
    {
    
    
        $this->m_token = $token;
        $this->m_encodingAesKey = $encodingAesKey;
        $this->m_corpId = $ownerKey;
	}
	

$token encodingAesKey分别对应以下图片内的值
在这里插入图片描述
坑我不能保存成功的问题参数 $ownerKey
我已为是corpid导致出现以下错误
在这里插入图片描述
最后改为
在这里插入图片描述
appkey后保存成功
测试代码

     /**
     * 钉钉订阅考勤事件测试
     */
  public   function onDing(){
    
    
	  
    	if ($this->request->isPost()) {
    
     
        $post = json_decode(file_get_contents("php://input"), true);   
		$crypt = new DingCallbackCrypto("你自己的","你自己的", "你自己的");
		  
			 $msg_signature=$this->request->param("msg_signature");
			 $timestamp= $this->request->param("timestamp");
		     $nonce= $this->request->param("nonce");  
			 $res=$crypt->getEncryptedMap("success");
		 
  return $res;
}    

猜你喜欢

转载自blog.csdn.net/taogunet/article/details/113257299