Before implementing the micro-channel pc sends messages via hook technology, micro-channels can be achieved if the binding Turing robot bot.
Download: http: //blog.yshizi.cn/131.html
Logic is as follows:
Let me briefly explain the steps.
- First, you need to download my micro letter aide, download address please refer to my blog post:
implement micro-channel micro Assistant letter pc hook through . - Turing robot application, and certification. Application Address , use api access and obtain apikey (Refer Turing robot's official website).
Use php to achieve access Turing robot api.
php codes are as follows:<?php
class Tuling123
{
private $apiKey;
private $secret;
private $text;
private $userId = 1;
private $selfInfo = '';public function __construct($apiKey, $userId, $selfInfo){
$this->apikey = $apiKey; $this->secret = $secret; $this->userId = $userId; $this->selfInfo = $selfInfo;
}
public function tuling($text, $raw = false){
$this->text = $text; $param = [ 'perception' => [ 'inputText' => [ 'text' => $this->text, ], 'selfInfo' => $this->selfInfo ], 'userInfo' => [ 'apiKey' => $this->apikey, 'userId' => $this->userId, ] ]; $result = json_decode('['.$this->post('http://openapi.tuling123.com/openapi/api/v2',json_encode($param)).']',true); return $raw ? $result : $result[0]['results'][0]['values']['text'];
}
private function post($url,$data){
$curl = curl_init(); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($curl, CURLOPT_URL, $url); $result = curl_exec($curl); curl_close($curl); return $result;
}
}
?>
TuLing.php
code package mainly Turing robot api
<?php
require __DIR__.'/TuLing.php';
/**
* 获取 post 参数; 在 content_type 为 application/json 时,自动解析 json
* @return array
*/
function initPostData()
{
if (empty($_POST)) {
$content = file_get_contents('php://input');
$post = (array)json_decode($content, true);
} else {
$post = $_POST;
}
return $post;
}
$selfInfo = [
'location' => [
'city' => '广州'
]
];
header('Content-Type:application/json');
$post = initPostData();
$userid=$post['wxid'];
$content=$post['content'];
str_replace // ( " ", "", "$ the userid") to remove " " microcells Turing user id id as the robot, the robot as Turing not contain user id " "
$ = new new Tuling123 Data ( 'your FIG. Ling robot apiKey ', str_replace ( " ", "", "$ the userid"), $ selfInfo);
$ Result = $ DATA-> tuling ($ Content);
$json['wxid'] = $userid;
$json['content'] = $result;
echo json_encode($json,JSON_UNESCAPED_UNICODE);
?>
wechatrobot.php
Before these two documents the Publisher. Wechatrobot.php address file access even after the release of micro-channel interface address assistant.
As I release the address is: http: //blog.yshizi.cn/wechatrobot.php
micro-channel configuration assistant as follows:
Then you can pull up a robot.