微信公眾平台開發筆記(二)

2021-06-20 01:15:03 字數 3125 閱讀 4767

public

function

responsemsg

()//接收資料

echo $resultstr

;//輸出結果

}else}

//這是對使用者傳送位址位置的回應,返回使用者天語預報文字,具體**分析我會在下一次詳細注釋

private

function

receivelocation

($object

),&output=xml&ak=cc56cc354df507bfd5fe907241cfb68e"

;$weatherapistr

=file_get_contents

($weatherurl

);$weatherapiobj

=******xml_load_string

($weatherapistr

);$placeobj

=$weatherapiobj

->

currentcity

;//讀取城市

$todaydata

=$weatherapiobj

->

results

->

result[0

]->

data

;$todayweather

=$weatherapiobj

->

results

->

result[0

]->

weather

;$todaywind

=$weatherapiobj

->

results

->

result[0

]->

wind

;$todaytemperature

=$weatherapiobj

->

results

->

result[0

]->

temperature

;$contentstr

="天氣,風力,溫度"

;$resultstr

=$this

->

transmittext

($object

,$contentstr

);return

$resultstr;}

所以可以建立6個這樣的方法(不知道這樣叫對不對,對於我這樣沒有php基礎的人來說)。

接下來是最後個模組,那就是傳送給使用者的模板,資料型別是xml,一種樹型結構的文字,下面我直插入一種文字模板,下次模板新增就在這函式裡面新增。

private

function

transmittext

($object

,$content

,$flag =0

)//只能只有3個引數,後面還會加入模板型別引數。

下面是上面具體所寫的。

<?

php//定義您的標識

define

("token"

,"weiixn"

);//請將 "weixin" 改為您命名的 token

$wechatobj

=new

wechat

();if

(isset

($_get

['echostr'

]))else

class

wechat

}private

function

checksignature

()else

}public

function

responsemsg

()//接收資料

echo $resultstr

;//輸出結果

}else

}private

function

receivelocation

($object

),&output=xml&ak=cc56cc354df507bfd5fe907241cfb68e"

;$weatherapistr

=file_get_contents

($weatherurl

);$weatherapiobj

=******xml_load_string

($weatherapistr

);$placeobj

=$weatherapiobj

->

currentcity

;//讀取城市

$todaydata

=$weatherapiobj

->

results

->

result[0

]->

data

;$todayweather

=$weatherapiobj

->

results

->

result[0

]->

weather

;$todaywind

=$weatherapiobj

->

results

->

result[0

]->

wind

;$todaytemperature

=$weatherapiobj

->

results

->

result[0

]->

temperature

;$contentstr

="天氣,風力,溫度"

;$resultstr

=$this

->

transmittext

($object

,$contentstr

);return

$resultstr;}

private

function

transmittext

($object

,$content

,$flag =0

)}?>

微信公眾平台開發學習筆記 二

經過上次的搭建後,自己嘗試做了乙個天氣的應答程式。目的主要是測試實時資訊的應答。主要用到了json和呼叫其餘 介面的知識,而在除錯的時候,主要用到了log4j的知識。將返回的輸入流轉換成字串 釋放資源 需要注意的是這裡呼叫的國家氣象局的介面獲取天氣資料,返回的其實是乙個json的陣列,要通過json...

PHP微信公眾開發筆記 五

日期 2014.9.3 今天做了身份驗證的功能,然後完善了下搜尋功能。其實主要的是將整個 結構整理了一番,應該可以說是模組化設計吧。因為我們之前提的功能需求中有 1 選單 查詢功能。我考慮到後期功能的擴充套件,就想將這些分模組來實現 選單模組 這樣,今後我們需要新增新的選單功能,可以直接在這個模組裡...

PHP微信公眾開發筆記 三

日期 2014.9.2 今天主要的任務是昨天提到的那個處理快取資訊的問題,我需要儲存一些訊息用來做二次判斷。首先,記錄一些php語法知識吧。1 php中字串的連線語法 在lua中,兩個字串的連線很簡單,加入有兩個字串 aaa bbb 需要將這兩個字串連線起來,只需要用兩個句點 便可以了 aaa bb...