/** * 钉钉签名算法 * @param string $noncestr * @param string $timestamp * @return string */ private static function sign($noncestr, $timestamp) { $jsapi_ticket = parent::$config['jsapi_ticket']; if (empty($jsapi_ticket)) { $jsapi_ticket = Token::jsapi(); } $signArr = ['jsapi_ticket' => $jsapi_ticket, 'noncestr' => $noncestr, 'timestamp' => $timestamp, 'url' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']]; ksort($signArr); $signStr = urldecode(http_build_query($signArr)); return sha1($signStr); }
/** * POST 方式请求接口 * @param string $api * @param array $params * @return array|boolean */ public static function post($api, $params) { $access_token = Dingtalk::config('access_token'); if (empty($access_token)) { $access_token = Token::get(); } $url = Dingtalk::$baseUrl . $api . '?access_token=' . $access_token; $result = self::http($url, 'POST', json_encode($params, JSON_UNESCAPED_UNICODE), Dingtalk::$headers); if ($result !== false) { $result = json_decode($result, true); if ($result['errcode'] == 0) { return $result; } else { Dingtalk::error($result['errmsg']); return false; } } else { return false; } }