0
点赞
收藏
分享

微信扫一扫

在Lumen中引入钉钉SDK


最近在用Lumen开发钉钉企业内部应用,需要调用钉钉的SDK。不得不说,钉钉开发文档写的真是感人,开发的时候那是相当刺激。在使用SDK的时候遇到不少坑,钉钉的文档写的不是很详细,记录下在Laravel中集成DingTalk SDK的方法:

1.首先在​​http://open-doc.dingtalk.com/microapp/serverapi2/vzzrkv​​中下载PHP版本SDK。解压后文件目录如图在Lumen中引入钉钉SDK_php

这里我只用到dingtalk中的文件,删除aliyun、QimenCloud目录,保留top目录Autoloader.php和TopSdk.php文件。

  1. 在composer.json中:
"autoload": {
"classmap": [
"database"
],
"files":[
"app/Packages/taobao/TopSdk.php"
],
"psr-4": {
"App\\": "app/"
}

},

然后执行composer dump-autoload

  1. 执行完毕后,在Controller中就可以直接使用DingTalk SDK了。测试结果如下(注意要加‘ \ ’):
$c = new \DingTalkClient(\DingTalkConstant::$CALL_TYPE_OAPI,\DingTalkConstant::$METHOD_POST , \DingTalkConstant::$FORMAT_JSON);
var_dump($c);

打印出结果如下:

object(DingTalkClient)#276 (9) { ["gatewayUrl"]=> string(34) "http://eco.taobao.com/router/rest" ["format"]=> string(4) "json" ["connectTimeout"]=> NULL ["readTimeout"]=> NULL ["apiCallType"]=> string(4) "oapi" ["httpMethod"]=> string(4) "POST" ["checkRequest"]=> bool(true) ["apiVersion":protected]=> string(3) "2.0" ["sdkVersion":protected]=> string(25) "dingtalk-sdk-php-20161214" }

遇到的坑:

  1. 在调用DingTalkClient的execute方法获取token的时候,报错如下:
Missing argument 7 for DingTalkClient::_executeOapi(), called in /Web/proj/app/Packages/taobao/dingtalk/DingTalkClient.php on line 328 and defined

查看DingTalkClient.php文件,328行

public function execute($request, $session = null,$bestUrl = null){
if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
return $this->_executeOapi($request, $session, $bestUrl, null, null, null);
}else{
return $this->_execute($request, $session, $bestUrl);
}
}

查看_executeOapi方法的代码:

private function _executeOapi($request, $session = null,$bestUrl = null,$accessKey, $accessSecret, $suiteTicket, $corpId)

此处发现_executeOapi方法需要传7个参数,而在execute中只传了6个参数。修改后的代码如下:

public function execute($request, $session = null,$bestUrl = null){
if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
return $this->_executeOapi($request, $session, $bestUrl, null ,null, null, null);
}else{
return $this->_execute($request, $session, $bestUrl);
}
}


举报

相关推荐

0 条评论