如何使用騰訊云云主機(jī)搭建微信服務(wù)器

首先我們這里要有一臺騰訊云主機(jī),作為學(xué)生的我們,說么幸福,一元一個月。參看:


然后購買之后,我們選擇centos系統(tǒng)作為本次的操作的對象,首先我們要搭建一下LAMP

環(huán)境,具體操作如下:

(參見我上篇文章《 centos 如何通過yum源搭建lamp環(huán)境》)

然后我們在/var/www/html文件下創(chuàng)建一個index.php文件

具體命令:

vi index.php


/**

* wechat php test

*/

//define your token

define("TOKEN", "weixin");

$wechatObj = new wechatCallbackapiTest();

$wechatObj->valid();

class wechatCallbackapiTest

{

public function valid()

{

$echoStr = $_GET["echostr"];

//valid signature , option

if($this->checkSignature()){

echo $echoStr;

exit;

}

}

public function responseMsg()

{

//get post data, May be due to the different environments

$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

//extract post data

if (!empty($postStr)){

/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,

the best way is to check the validity of xml by yourself */

libxml_disable_entity_loader(true);

$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

$fromUsername = $postObj->FromUserName;

$toUsername = $postObj->ToUserName;

$keyword = trim($postObj->Content);

$time = time();

$textTpl = "

%s

0

";

if(!empty( $keyword ))

{

$msgType = "text";

$contentStr = "Welcome to wechat world!";

$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);

echo $resultStr;

}else{

echo "Input something...";

}

}else {

echo "";

exit;

}

}

private function checkSignature()

{

// you must define TOKEN by yourself

if (!defined("TOKEN")) {

throw new Exception('TOKEN is not defined!');

}

$signature = $_GET["signature"];

$timestamp = $_GET["timestamp"];

$nonce = $_GET["nonce"];

$token = TOKEN;

$tmpArr = array($token, $timestamp, $nonce);

// use SORT_STRING rule

sort($tmpArr, SORT_STRING);

$tmpStr = implode( $tmpArr );

$tmpStr = sha1( $tmpStr );

if( $tmpStr == $signature ){

return true;

}else{

return false;

}

}

}

?>

然后保存,我們這個時候去微信公共平臺申請一個測試號


在url 填上http://ip? token:weixin

這個時候我們可以點(diǎn)擊提交,如果一次失敗,點(diǎn)擊多次。然后就這樣搭建成功了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、開啟公眾號開發(fā)者模式 公眾平臺的技術(shù)文檔目的為了簡明扼要的交代接口的使用,語句難免苦澀難懂,甚至對于不同的讀者...
    good7758閱讀 1,663評論 0 1
  • 輸了就是輸了,無論再多說什么,都只是無力的借口。好笑,當(dāng)自己的能力無法對得起自己的驕傲?xí)r,所做出的一切舉動都是那么...
    隋懿閱讀 151評論 0 0
  • 喜樂操練90天——73《一同慶賀!》 一個罪人悔改,在天上也要這樣為他歡喜,較比為九十九個不用悔改的義人歡喜更大。...
    午后的咖啡與茶閱讀 690評論 0 0
  • 1
    why潑灑閱讀 216評論 0 0
  • 今天拿了809的產(chǎn)品,還是在練習(xí)洗臉,佳欣姐做了一遍全的,讓我拍視頻照做,不懂的再問她。 晚上的時候來了一個大姐,...
    挽箏閱讀 167評論 0 0

友情鏈接更多精彩內(nèi)容