/** * 分词 */ public static function segger($paramArr) { $options = array('content' => '', 'segger' => 'default', 'mustIn' => 0, 'num' => 10); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); $outArr = array(); $content = strip_tags(mb_convert_encoding($content, "utf-8", "gbk")); #$data = API_Http::curlPage(array('url'=>self::$seggerUrl . "?segger=default&content=".urlencode($content))); $data = API_Http::curlPost(array('url' => self::$seggerUrl, 'postdata' => array('segger' => $segger, 'cnt' => $num, 'content' => $content))); if ($data) { $dataArr = explode("\n", $data); foreach ($dataArr as $d) { if (!$d) { continue; } list($wd, $score) = explode("/", $d); if ($mustIn && $score < 0) { continue; } $outArr[] = array('wd' => $wd, 'score' => $score); } } return $outArr; }
/** * 利用curl POST数据 */ public static function curlPost($paramArr) { return API_Http::curlPost($paramArr); }
/** * 给员工发送消息 * */ public static function sendUserMsg($paramArr) { $options = array('toUserArr' => '', 'toPartyArr' => '', 'msgContent' => '', 'msgType' => 'text', 'safe' => 0, 'agentId' => ''); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); $assessToken = API_Item_Open_WeixinQy::getAccessToken(); $url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$assessToken}"; $data = array(); if (empty($toUserArr)) { return false; } $toUser = !empty($toUserArr) && is_array($toUserArr) ? implode("|", $toUserArr) : $toUserArr; $toParty = !empty($toPartyArr) && is_array($toPartyArr) ? implode("|", $toPartyArr) : $toPartyArr; !empty($toUser) && ($data['touser'] = $toUser); !empty($toParty) && ($data['toparty'] = $toParty); $data['msgtype'] = $msgType; $data['agentid'] = !empty($agentId) ? $agentId : self::$agentId; if (!empty($msgContent)) { $msgContent = urlencode(iconv('GBK', 'UTF-8', $msgContent)); switch ($msgType) { #文本 case "text": $data['text'] = array('content' => $msgContent); break; #图片 #图片 case "image": $data['image'] = array('media_id' => $msgContent); break; #声音 #声音 case "voice": $data['voice'] = array('media_id' => $msgContent); break; #视频 #视频 case "video": $data['video'] = $msgContent; break; #视频 #视频 case "file": $data['file'] = array('media_id' => $msgContent); break; #新闻 #新闻 case "news": $data['news'] = $msgContent; break; } } $data['safe'] = $safe; $jsonStr = urldecode(json_encode($data)); $state = API_Http::curlPost(array('url' => $url, 'postdata' => $jsonStr)); return api_json_decode($state); }
/** * 发送模板信息接口 * @param type $paramArr * @return type */ public static function sendTemplateMessage($paramArr) { $options = array('appId' => '', 'appSecret' => '', 'dataArr' => ''); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); if (empty($appId) || empty($appSecret) || empty($dataArr)) { return false; } #获得access_token $tokenDataArr = self::getAccessToken(array('appId' => $appId, 'appSecret' => $appSecret)); #获得 access_token $accessToken = ""; if (!empty($tokenDataArr['state'])) { $accessToken = $tokenDataArr['data']; } else { return false; } $jsonStr = ""; $jsonStr = API_Http::curlPost(array('url' => 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $accessToken, 'postdata' => !empty($dataArr) ? api_json_encode($dataArr) : '')); $jsonArr = array(); $jsonArr = api_json_decode($jsonStr); if (!empty($jsonArr['errmsg'])) { if ($jsonArr['errmsg'] == 'ok' && $jsonArr['errcode'] == '0') { return true; } } else { return false; } }