|
本帖最后由 riskstar 于 2014-12-16 11:51 编辑
在网上找到了一个通过Wordpress的xmlrpc接口发布文章到Wordpress的Autoit脚本,就想给写个GUI,但是在调用的时候一直不成功,烦请大家指点一下问题出在哪里,谢谢!
原始的WordPress发布程序#include <Constants.au3>
$title = 'title' ;文章标题
$content = '<strong>content</strong>' ;文章内容 ,支持 html标签
;~ $content = FileRead("yourpost.txt") ; 若文章编辑好后放文本里面
$tag = "tag,new,actgod" ;设置tag 标签,多个用,隔开
$categorie = "categories" ;分类,支持中文,需先设置好
$username = 'admin' ;登陆帐号,即后台登陆帐号
$pw = 'password' ; 密码
; 组织 post 内容
$p = '<?xml version="1.0" encoding="utf-8"?>'
$p &= '<methodCall><methodName>metaWeblog.newPost</methodName><params>'
$p &= '<param><value><string>0</string></value></param>'
$p &= '<param><value><string>' & $username & '</string></value></param>'
$p &= '<param><value><string>' & $pw & '</string></value></param>'
$p &= '<param><value><struct><member><name>title</name><value>'
$p &= '<string>' & $title & '</string></value></member><member><name>'
$p &= 'description</name><value><string><![CDATA[' & $content & ']]></string></value></member>'
$p &= '<member><name>mt_keywords</name><value><string>' & $tag & '</string></value></member>'
$p &= '<member><name>categories</name><value><array><data><value><string><![CDATA[' & $categorie & ']]></string>'
$p &= '</value></data></array></value></member></struct></value></param>'
$p &= '<param><value><boolean>publish</boolean></value></param>'
$p &= '</params></methodCall>'
; api 接口
$api = 'http://www.your-website.com/xmlrpc.php'
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", $api, False)
$oHTTP.Send($p)
;~ 若不需要显示返回信息,将下行加 ; 注释
ConsoleWrite($oHTTP.ResponseText)
编写的GUI代码#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=G:\D\autoit3\test\Wordpress发布器.kxf
$Form1 = GUICreate("Wordpress发布器", 683, 568, 192, 124)
$Label1 = GUICtrlCreateLabel("主机地址:", 48, 40, 64, 17)
$Input1 = GUICtrlCreateInput("", 112, 40, 545, 21)
$Label2 = GUICtrlCreateLabel("用户名:", 48, 74, 52, 17)
$Label3 = GUICtrlCreateLabel("密码:", 408, 78, 40, 17)
$Label4 = GUICtrlCreateLabel("标题:", 48, 110, 40, 17)
$Input2 = GUICtrlCreateInput("", 110, 110, 545, 21)
GUICtrlCreateEdit("", 112, 168, 537, 233)
GUICtrlSetData(-1, "Edit1")
$Label5 = GUICtrlCreateLabel("栏目:", 48, 440, 40, 17)
$Label6 = GUICtrlCreateLabel("标签:", 372, 438, 40, 17)
$Input3 = GUICtrlCreateInput("", 108, 435, 201, 21)
$Input4 = GUICtrlCreateInput("", 438, 438, 201, 21)
$Label7 = GUICtrlCreateLabel("内容:", 49, 166, 40, 17)
$Input5 = GUICtrlCreateInput("", 106, 74, 201, 21)
$Input6 = GUICtrlCreateInput("", 450, 71, 209, 21)
$Button1 = GUICtrlCreateButton("发布", 296, 488, 137, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
整合后出错的程序#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Region ### START Koda GUI section ### Form=G:\D\autoit3\test\Wordpress发布器.kxf
$Form1 = GUICreate("Wordpress发布器", 683, 568, 192, 124)
$Label1 = GUICtrlCreateLabel("主机地址:", 48, 40, 64, 17)
$Input1 = GUICtrlCreateInput("", 112, 40, 545, 21)
$Label2 = GUICtrlCreateLabel("用户名:", 48, 74, 52, 17)
$Label3 = GUICtrlCreateLabel("密码:", 408, 78, 40, 17)
$Label4 = GUICtrlCreateLabel("标题:", 48, 110, 40, 17)
$Input2 = GUICtrlCreateInput("", 110, 110, 545, 21)
$Edit1 = GUICtrlCreateEdit("", 112, 168, 537, 233)
$Label5 = GUICtrlCreateLabel("栏目:", 48, 440, 40, 17)
$Label6 = GUICtrlCreateLabel("标签:", 372, 438, 40, 17)
$Input3 = GUICtrlCreateInput("", 108, 435, 201, 21)
$Input4 = GUICtrlCreateInput("", 438, 438, 201, 21)
$Label7 = GUICtrlCreateLabel("内容:", 49, 166, 40, 17)
$Input5 = GUICtrlCreateInput("", 106, 74, 201, 21)
$Input6 = GUICtrlCreateInput("", 450, 71, 209, 21)
$Button1 = GUICtrlCreateButton("发布", 296, 488, 137, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Func post2wordpres ()
$title = GUICtrlRead($Input2) ;文章标题
$content = GUICtrlRead($Edit1) ;文章内容 ,支持 html标签
;~ $content = FileRead("yourpost.txt") ; 若文章编辑好后放文本里面
$tag = GUICtrlRead($Input4) ;设置tag 标签,多个用,隔开
$categorie = GUICtrlRead($Input3) ;分类,支持中文,需先设置好
$username = GUICtrlRead($Input5) ;登陆帐号,即后台登陆帐号
$pw = GUICtrlRead($Input6) ; 密码
; 组织 post 内容
$p = '<?xml version="1.0" encoding="utf-8"?>'
$p &= '<methodCall><methodName>metaWeblog.newPost</methodName><params>'
$p &= '<param><value><string>0</string></value></param>'
$p &= '<param><value><string>' & $username & '</string></value></param>'
$p &= '<param><value><string>' & $pw & '</string></value></param>'
$p &= '<param><value><struct><member><name>title</name><value>'
$p &= '<string>' & $title & '</string></value></member><member><name>'
$p &= 'description</name><value><string><![CDATA[' & $content & ']]></string></value></member>'
$p &= '<member><name>mt_keywords</name><value><string>' & $tag & '</string></value></member>'
$p &= '<member><name>categories</name><value><array><data><value><string><![CDATA[' & $categorie & ']]></string>'
$p &= '</value></data></array></value></member></struct></value></param>'
$p &= '<param><value><boolean>publish</boolean></value></param>'
$p &= '</params></methodCall>'
; api 接口
$api = GUICtrlRead($Input1)
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", $api, False)
$oHTTP.Send($p)
;~ 若不需要显示返回信息,将下行加 ; 注释
ConsoleWrite($oHTTP.ResponseText)
EndFunc
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
post2wordpres()
EndSwitch
WEnd
|
|