function matchEngine($content) { global $reg_arr, $biaoqing; foreach ($reg_arr as $key => $value) { if (preg_match($key, $content, $matches)) { switch ($value) { case 'dream': $data = dream($matches[2]); break; case 'translate': $data = translateAPI($matches[2]); break; case 'biaoqing': $data = $biaoqing[rand(0, count($biaoqing) - 1)]; break; case 'changeSimsimiKey': $s = new SaeStorage(); $s->write('simsimi', 'simi.txt', $matches[2]); $data = '更改成功!'; break; case 'md5': $data = md5($matches[2]); break; case 'qrcode': $qrcode = 'http://chart.apis.google.com/chart?cht=qr&chs=400x400&choe=UTF-8&chl=' . $matches[2]; $data = array(array('title' => $matches[2], 'cover' => $qrcode, 'link' => $qrcode)); break; case 'bingSearch': $bingweb = bing($matches[2], 'Web'); $bingimage = bing($matches[2], 'Image'); $data = array(array('title' => $matches[2], 'note' => '', 'cover' => $bingimage[0], 'link' => '')); //max:7 for ($i = 0; $i < 5; $i++) { array_push($data, array('title' => $bingweb[$i]['title'] . "\n" . '------------------------------------------', 'note' => $bingweb[$i]['description'], 'cover' => '', 'link' => $bingweb[$i]['url'])); } break; case 'wiki': $wiki = wiki($matches[2], $lng); $data = array(); for ($i = 0; $i < 5; $i++) { array_push($data, array('title' => $wiki[$i]['title'] . "\n" . '------------------------------------------', 'note' => $wiki[$i]['snippet'], 'cover' => '', 'link' => 'http://zh.wikipedia.org/wiki/' . $wiki[$i]['title'])); } break; case 'doubanMovie1': $m = doubanMovies($matches[2]); $data = array(array('title' => $m[0]['title'], 'note' => $m[0]['year'] . ' ' . $m[0]['average'], 'cover' => $m[0]['images']->large, 'link' => $m[0]['alt'])); for ($i = 1; $i <= 5; $i++) { array_push($data, array('title' => $m[$i]['title'], 'note' => '又名:' . $m[$i]['original_title'] . "\n" . '上映日期:' . $m[$i]['year'] . "\n" . '评价:' . $m[$i]['average'], 'cover' => $m[$i]['images']->small, 'link' => $m[$i]['alt'])); } break; case 'doubanMovie2': $m = doubanMovies($matches[2]); $movie = doubanMovie($m[0]['id']); $xinxi = '又名:'; foreach ($movie['aka'] as $value) { $xinxi .= $value . '/'; } $xinxi .= "\n" . '上映日期:' . $movie['year'] . "\n" . '制片国家:'; foreach ($movie['countries'] as $value) { $xinxi .= $value . '/'; } $xinxi .= "\n" . '类型:'; foreach ($movie['genres'] as $value) { $xinxi .= $value . '/'; } $xinxi .= "\n" . '评价:' . $movie['average']; $data = array(array('title' => $movie['title'], 'cover' => $movie['images'], 'link' => $movie['mobile_url']), array('note' => $xinxi, 'link' => $movie['mobile_url']), array('title' => '简介', 'note' => $movie['summary'], 'link' => $movie['mobile_url']), array('title' => '导演', 'note' => $movie['directors'][0]->name, 'cover' => $movie['directors'][0]->avatars->small, 'link' => $movie['directors'][0]->alt), array('title' => '主演', 'note' => $movie['casts'][0]->name, 'cover' => $movie['casts'][0]->avatars->small, 'link' => $movie['casts'][0]->alt)); break; case 'doubanBook1': $b = doubanBooks($matches[2]); $data = array(array('title' => $b[0]['title'], 'note' => $b[0]['author'][0] . ' ' . $b[0]['average'], 'cover' => $b[0]['images']->large, 'link' => $b[0]['alt'])); for ($i = 1; $i <= 4; $i++) { array_push($data, array('title' => $b[$i]['title'], 'note' => '作者:' . $b[$i]['author'][0] . "\n" . '出版社:' . $b[$i]['publisher'] . "\n" . '出版日期:' . $b[$i]['pubdate'] . "\n" . '价格:' . $b[$i]['price'] . "\n" . '评价:' . $b[$i]['average'] . "\n" . '导言:' . $b[$i]['summary'], 'cover' => $b[$i]['images']->small, 'link' => $b[$i]['alt'])); } break; case 'doubanBook2': $b = doubanBooks($matches[2]); $bk = doubanBook($b[0]['id']); $data = array(array('title' => $bk['title'], 'cover' => $bk['images'], 'link' => $bk['alt']), array('note' => '作者:' . $bk['author'][0] . "\n" . '出版社:' . $bk['publisher'] . "\n" . '出版日期:' . $bk['pubdate'] . "\n" . '价格:' . $bk['price'] . "\n" . '评价:' . $bk['average'], 'link' => $bk['alt']), array('title' => '导言:', 'note' => $bk['summary'], 'link' => $bk['alt'])); break; case 'doubanMusic1': $m = doubanMusics($matches[2]); $data = array(array('title' => $m[0]['title'], 'note' => $m[0]['average'], 'cover' => $m[0]['image'], 'link' => $m[0]['alt'])); for ($i = 1; $i <= 4; $i++) { array_push($data, array('title' => $m[$i]['title'], 'note' => '作者:' . $m[$i]['author'][0]->name . "\n" . '出版社:' . $m[$i]['publisher'][0] . "\n" . '出版日期:' . $m[$i]['pubdate'][0] . "\n" . '表演者:' . $m[$i]['singer'][0] . "\n" . '评价:' . $m[$i]['average'] . "\n" . '类型:' . $m[$i]['version'][0], 'cover' => $m[$i]['image'], 'link' => $m[$i]['alt'])); } break; case 'doubanMusic2': $m = doubanMusics($matches[2]); $mu = doubanMusic($m[0]['id']); $data = array(array('title' => $mu['title'], 'cover' => $mu['image'], 'link' => $mu['mobile_link']), array('note' => '表演者:' . $mu['singer'][0] . "\n" . '专辑类型:' . $mu['version'][0] . "\n" . '发行时间:' . $mu['pubdate'][0] . "\n" . '作者:' . $mu['author'][0]->name . "\n" . '出版者:' . $mu['publisher'][0] . "\n" . '评价:' . $mu['average'], 'link' => $mu['mobile_link']), array('title' => '简介:', 'note' => $mu['summary'], 'link' => $mu['mobile_link'])); break; case 'moments1': $moment = $matches[2]; $time = time(); $date = date("Y-m-d H:i:s", time()); $mysql = new SaeMysql(); $res = $mysql->getData("SELECT alias FROM info WHERE FromUserName='******'"); $alias = $res[0]['alias']; if (!$alias) { $data = '由于你是第一次发送动态,请按照以下格式回复基本信息:' . "\n" . '昵称:+你的昵称'; } else { $mysql->runSql("INSERT INTO moments(FromUserName,alias,moment,time,date) VALUES ('{$openid}','{$alias}','{$moment}',{$time},'{$date}')"); $data = "发送成功,你可以现在上传一张图片作为配图,当然也可以不上传啦。回复[动态]查看"; } break; case 'moments2': $alias = $matches[2]; $mysql = new SaeMysql(); $res = $mysql->getData("SELECT * FROM info"); $num = 0; while ($res[$num]) { if ($alias == $res[$num]['alias'] || $alias == '小u' || $alias == 'urinx') { $t = 1; } elseif ($openid == $res[$num]['FromUserName']) { $u = 1; } $num++; } if ($t) { $data = '该用户名已被注册,请重新输入'; } else { if ($u) { $mysql->runSql("UPDATE info SET alias='{$alias}' WHERE FromUserName='******'"); $data = '更改成功!'; } else { $mysql->runSql("INSERT INTO info(FromUserName,alias) VALUES ('{$openid}','{$alias}')"); $data = '注册成功!'; } } break; default: # code... break; } } } return $data; }
$xinxi .= $value . '/'; } $xinxi .= "\n" . '类型:'; foreach ($movie['genres'] as $value) { $xinxi .= $value . '/'; } $xinxi .= "\n" . '评价:' . $movie['average']; $data = array(array('title' => $movie['title'], 'cover' => $movie['images'], 'link' => $movie['mobile_url']), array('note' => $xinxi, 'link' => $movie['mobile_url']), array('title' => '简介', 'note' => $movie['summary'], 'link' => $movie['mobile_url']), array('title' => '导演', 'note' => $movie['directors'][0]->name, 'cover' => $movie['directors'][0]->avatars->small, 'link' => $movie['directors'][0]->alt), array('title' => '主演', 'note' => $movie['casts'][0]->name, 'cover' => $movie['casts'][0]->avatars->small, 'link' => $movie['casts'][0]->alt)); } elseif (preg_match('/^(bs:)(.+)/i', $content, $matches)) { $b = doubanBooks($matches[2]); $data = array(array('title' => $b[0]['title'], 'note' => $b[0]['author'][0] . ' ' . $b[0]['average'], 'cover' => $b[0]['images']->large, 'link' => $b[0]['alt'])); for ($i = 1; $i <= 4; $i++) { array_push($data, array('title' => $b[$i]['title'], 'note' => '作者:' . $b[$i]['author'][0] . "\n" . '出版社:' . $b[$i]['publisher'] . "\n" . '出版日期:' . $b[$i]['pubdate'] . "\n" . '价格:' . $b[$i]['price'] . "\n" . '评价:' . $b[$i]['average'] . "\n" . '导言:' . $b[$i]['summary'], 'cover' => $b[$i]['images']->small, 'link' => $b[$i]['alt'])); } } elseif (preg_match('/^(b:)(.+)/i', $content, $matches)) { $b = doubanBooks($matches[2]); $bk = doubanBook($b[0]['id']); $data = array(array('title' => $bk['title'], 'cover' => $bk['images'], 'link' => $bk['alt']), array('note' => '作者:' . $bk['author'][0] . "\n" . '出版社:' . $bk['publisher'] . "\n" . '出版日期:' . $bk['pubdate'] . "\n" . '价格:' . $bk['price'] . "\n" . '评价:' . $bk['average'], 'link' => $bk['alt']), array('title' => '导言:', 'note' => $bk['summary'], 'link' => $bk['alt'])); } elseif (preg_match('/^(ms:)(.+)/i', $content, $matches)) { $m = doubanMusics($matches[2]); $data = array(array('title' => $m[0]['title'], 'note' => $m[0]['average'], 'cover' => $m[0]['image'], 'link' => $m[0]['alt'])); for ($i = 1; $i <= 4; $i++) { array_push($data, array('title' => $m[$i]['title'], 'note' => '作者:' . $m[$i]['author'][0]->name . "\n" . '出版社:' . $m[$i]['publisher'][0] . "\n" . '出版日期:' . $m[$i]['pubdate'][0] . "\n" . '表演者:' . $m[$i]['singer'][0] . "\n" . '评价:' . $m[$i]['average'] . "\n" . '类型:' . $m[$i]['version'][0], 'cover' => $m[$i]['image'], 'link' => $m[$i]['alt'])); } } elseif (preg_match('/^(m:)(.+)/i', $content, $matches)) { $m = doubanMusics($matches[2]); $mu = doubanMusic($m[0]['id']); $data = array(array('title' => $mu['title'], 'cover' => $mu['image'], 'link' => $mu['mobile_link']), array('note' => '表演者:' . $mu['singer'][0] . "\n" . '专辑类型:' . $mu['version'][0] . "\n" . '发行时间:' . $mu['pubdate'][0] . "\n" . '作者:' . $mu['author'][0]->name . "\n" . '出版者:' . $mu['publisher'][0] . "\n" . '评价:' . $mu['average'], 'link' => $mu['mobile_link']), array('title' => '简介:', 'note' => $mu['summary'], 'link' => $mu['mobile_link'])); } elseif (preg_match('/^(:)(.+)/i', $content, $matches)) { $moment = $matches[2]; $time = time();
<?php header("content-Type: text/html; charset=utf-8"); function doubanBooks($word) { $doubanBook_api_url = 'https://api.douban.com/v2/book/search?count=5&q='; $result = file_get_contents($doubanBook_api_url . $word); $jsondata = json_decode($result); $book = array(); foreach ($jsondata->books as $value) { array_push($book, array('average' => $value->rating->average, 'author' => $value->author, 'pubdate' => $value->pubdate, 'images' => $value->images, 'alt' => $value->alt, 'title' => $value->title, 'publisher' => $value->publisher, 'summary' => $value->summary, 'price' => $value->price, 'tags' => $value->tags, 'id' => $value->id)); } return $book; } function doubanBook($id) { $doubanBook_api_url = 'https://api.douban.com/v2/book/'; $result = file_get_contents($doubanBook_api_url . $id); $jsondata = json_decode($result); $book = array('average' => $jsondata->rating->average, 'author' => $jsondata->author, 'pubdate' => $jsondata->pubdate, 'images' => $jsondata->images, 'alt' => $jsondata->alt, 'title' => $jsondata->title, 'publisher' => $jsondata->publisher, 'summary' => $jsondata->summary, 'price' => $jsondata->price, 'tags' => $jsondata->tags); return $book; } $m = doubanBooks('日本文学'); print_r($m);