pythonsae微信
A. 目前想在新浪SAE上部署個python程序,來抓取一些網站上的東西,在雲端生成xml來做rss。問
sae可以存啊,有特殊的api,你看看storage
B. 我想用python自動接收微信公眾平台接收到的消息,根據消息內容再做出回復。不知道怎麼搞
現在都有微信公眾平台的智能機器人了啊,你到千呼萬喚微信公眾平台導航網站看下,在微信網路裡面有現有的源碼下載,照著教程設置就可以了!
C. 用sae開發微信和微信自帶功能有什麼區別
行家可以用sae實現許多微信平台沒法實現的功能,不過能實現哪些功能,微信基本限定死了,介面擺在那兒呢
D. 微信Token驗證不過,用的是微信教程里的模板php在sae上導入的URL,token 是weixin
Token 要自己在微信那設置的
E. 新浪雲PythonSAE伺服器如何配置
不一樣的程序可能會有不同的安裝要求,具體要看你是什麼程序的,我是用的小鳥雲伺服器。不懂的可以問下他們客服
F. 求助:為什麼SAE和微信公眾平台url token介面配置不上 一直顯示配置失敗
下載上傳官方的介面測試文件到SAE上,在echo $_GET["echostr"];前加上header('content-type:text');這一句就驗證成功了,你可以試試這種方法。
constTOKEN='anbaojia';
functioncheckSignature()
{
$signature=$_GET["signature"];
$timestamp=$_GET["timestamp"];
$nonce=$_GET["nonce"];
$token=self::TOKEN;
$tmpArr=array($token,$timestamp,$nonce);
sort($tmpArr,SORT_STRING);
$tmpStr=implode($tmpArr);
$tmpStr=sha1($tmpStr);
if($tmpStr==$signature){
header('content-type:text');
echo$_GET["echostr"];
}else{
returnfalse;
}
}
TIPS:必須確認微信公眾平台上填寫的token和介面文件里的token值是一致的哦。
G. 微信公眾平台 python安裝哪裡
微信公眾平台 python安裝哪裡
SAE創建python程序,在index.wsgi輸入以下代碼,在微信驗證輸入xx.sinaapp.com,token任意,完成驗證,微信中回復hello
#utf-8
import sae
import urlparse
import xml.etree.ElementTree as ET
def app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/html; charset=utf-8')]
start_response(status, response_headers)
method=environ['REQUEST_METHOD']
if method=="GET":
query=environ['QUERY_STRING']
echostr=urlparse.parse_qs(query)['echostr']
return echostr
elif method=="POST":
post=environ['wsgi.input']
root = ET.parse(post)
fromUser=root.findtext(".//FromUserName")
toUser=root.findtext(".//ToUserName")
CreateTime=root.findtext(".//CreateTime")
texttpl='''<xml>
<ToUserName>'''+fromUser+'''</ToUserName>
<FromUserName>'''+toUser+'''</FromUserName>
<CreateTime>'''+CreateTime+'''</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[hello]]></Content>
</xml>'''
return texttpl
application = sae.create_wsgi_app(app)
H. 如何用Python進行微信二次開發
創建步驟:
1.申請免費且支持python的伺服器,新浪雲sae,新建SAE應用之後,有兩種代碼提交方式,建議使用SVN(因為git支持代碼提交,但不支持環境配置);
2.將對應版本的信息復制到微信開發-基本配置-URL,提交顯示錯誤,因為還沒有寫代碼,可以先用web框webpy架寫個網頁;
查看webpy使用說明:http://www.webpy.org/install.zh-cn
查看ase進行python開發入門說明:http://www.sinacloud.com/doc/sae/python/index.html
3.配置信息,告訴新浪雲需要什麼運行環境。點擊代碼管理-編輯代碼,將用到的第三方庫信息寫入config.yaml,注意破折號,冒號後面空格!!
libraries:
-name:webpy
version:"0.36"
-name:lxml
version:"2.3.4"
在index.wsgi文件中寫入python啟動程序
新建文件,寫入接受微信get請求驗證的Python文件
4.在index.wgsi中寫入以下信息:
#coding=utf-8
importos
importsae
importweb#配置web的路由
urls=(
'/weixin','WeixinInterface'
)
#拼接路徑
app_root=os.path.dirname(__file__)
templates_root=os.path.join(app_root,'templates')
#渲染模版
render=web.template.render(templates_root)
#啟動app
app=web.application(urls,globals()).wsgifunc()
application=sae.create_wsgi_app(app)
5.在自己編寫的Python文件中寫入微信驗證和接受信息的程序
#coding=utf-8
importhashlib
importweb
importtime
importos
fromlxmlimportetree
#hashlib用於加密,md5,hash等
#lxml用來解析xml文件
classWeixinInterface(object):
#初始化
def__init__(self):
#拼接路徑
self.app_root=os.path.dirname(__file__)
self.templates_root=os.path.join(self.app_root,'templates')
#渲染模版
self.render=web.template.render(self.templates_root)
#使用get方法,接收微信的get請求,看開發者文檔的說明
#http://mp.weixin.qq.com/wiki/8/.html
defGET(self):
data=web.input()
signature=data.signature#微信加密簽名
timestamp=data.timestamp#時間戳
nonce=data.nonce#隨機數
echostr=data.echostr#隨即字元串
token='zq90857'#自己設置的token
#將token、timestamp、nonce三個參數進行字典序排序
list=[token,timestamp,nonce]
list.sort()
#將三個參數字元串拼接成一個字元串進行sha1加密
sha1=hashlib.sha1()
map(sha1.update,list)
temStr=sha1.hexdigest()#加密
#判斷
iftemStr==signature:
returnechostr
6.假設接收文字信息,按照開發者文檔的要求,配置template文件夾下reply_text.xml文件
$defwith(toUser,fromUser,createtime,content)
<xml>
<ToUserName><![CDATA[$toUser]]></ToUserName>
<FromUserName><![CDATA[$fromUser]]></FromUserName>
<CreateTime>$createtime</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[$content]]></Content>
</xml>
I. 開發微信公眾平台時必須使用新浪雲SAE或者百度雲BAE作為伺服器嗎可以使用騰訊雲伺服器嗎
什麼雲都可以。我之前用過騰訊雲後來用的阿里雲。開發主要是你最好有一個備案的網址。因為純IP的有些功能你是用不了。代碼的話你可以下載一下PHP版本的demo。然後做網址或者域名的解析,解析完之後,把你的代碼上傳到對應網址解析的文件夾。你先寫個小程序,可以測試一下網址訪問有沒有問題,最後再部署微信的其他功能。
J. 如何在sae.上製作微信自定義菜單python
首先先獲取access_token,並保存與全局之中
def token(requset):
url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s' % (
Config.AppID, Config.AppSecret)
result = urllib2.urlopen(url).read()
Config.access_token = json.loads(result).get('access_token')
print 'access_token===%s' % Config.access_token
return HttpResponse(result)
利用上面獲得的access_token,創建自定義表單
def createMenu(request):
url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s" % Config.access_token
data = {
"button":[
{
"name":"看美圖",
"sub_button":[
{
"type":"click",
"name":"美圖",
"key":"meitu"
},
{
"type":"view",
"name":"精選",
"url":"http://m.jb51.net/photos"
},
{
"type":"view",
"name":"回顧",
"url":"http://m.qzone.com/infocenter?g_f=#2378686916/mine"
},
{
"type":"view",
"name":"美圖app",
"url":"http://jb51.net/app/app.html"
}]
},
{
"name":"看案例",
"sub_button":[
{
"type":"click",
"name":"全部風格",
"key":"style"
},
{
"type":"click",
"name":"全部戶型",
"key":"houseType"
},
{
"type":"click",
"name":"全部面積",
"key":"area"
},
{
"type":"view",
"name":"更多案例",
"url":"http://m.jb51.net/projects"
}]
},
{
"type":"view",
"name":"設計申請",
"url":"http://jb51.net/zhuanti/freedesign.jsp?src=3"
}
]
}
#data = json.loads(data)
#data = urllib.urlencode(data)
req = urllib2.Request(url)
req.add_header('Content-Type', 'application/json')
req.add_header('encoding', 'utf-8')
response = urllib2.urlopen(req, json.mps(data,ensure_ascii=False))
result = response.read()
return HttpResponse(result)