上一篇文章中写了lua对接水仙后台,不过发现不能支持图片上传,比如修改头像等,通过修改,支持了
require "import"
import "http"
shuixian={
post=function(moduleName,method,postdata,filedata,call)
local url="http://shuixian.ltd/main/api/"
if(filedata==nil) then
content,cookie,code,header=http.post(url..moduleName.."/"..method..".php",postdata)
call(code,content,cookie,header)
else
content,cookie,code,header=http.upload(url..moduleName.."/"..method..".php",postdata,filedata)
call(code,content,cookie,header)
end
end
}
import "shuixian"
shuixian.api(模块名,方法名,提交参数(可为表或字符串),文件参数(可为表或字符串),返回参数)
例子:以用户系统-用户注册为例
shuixian.api("user","register",postdata,function(code,content,cookie,header))
--[[
在水仙后台找到对应系统对应方法的提交接口,如用户修改接口:
http://shuixian.ltd/main/api/user/user_set.php
则上面方法的模块名和方法名如下:
http://shuixian.ltd/main/api/{模块名}/{方法名}.php
postdata说明:
以用户系统-用户修改接口为例,官方示例如下:
提交参数{
admin=管理员账号
user=用户账号
password=用户密码
project=要修改的信息(例:name、signatrue、password、head、wallet)
例如:
project=name(修改昵称)
name=要修改的昵称
project=signatrue(修改签名)
signatrue=要修改的签名
project=password(修改密码)
new_password=要修改的新密码
project=head(修改头像)
project=wallet(扣除用户积分)
num=扣除的数量
project=mail(修改邮箱)
mail=新邮箱
code=验证码
}
-- 以修改头像为例
postdata={
admin="管理员账号",
user="注册账号",
password="用户密码",
project="head"
}
filedata={
head="/storage/emulated/0/Pictures/Image.jpg" -- 头像图片的路径
}
返回参数说明:
code:响应代码,2xx表示成功,4xx表示请求错误,5xx表示服务器错误,-1表示出错
content:内容,如果code为-1,则为出错信息
cookie:服务器返回的用户身份识别信息
header:服务器返回的头信息
解析返回内容:
使用cjson等json包解析
result=cjson.decode(content)
if(result.code==1) then
print("注册成功")
elseif(result.code==0) then
print("注册失败-"..result.msg)
else
print("程序错误-"..result.msg)
end
]]
import "cjson"
import "http"
shuixian={
post=function(moduleName,method,postdata,filedata,call)
local url="http://shuixian.ltd/main/api/"
if(filedata==nil) then
content,cookie,code,header=http.post(url..moduleName.."/"..method..".php",postdata)
call(code,content,cookie,header)
else
content,cookie,code,header=http.upload(url..moduleName.."/"..method..".php",postdata,filedata)
call(code,content,cookie,header)
end
end
}
postdata={
admin="自己在水仙后台的管理员账号,也就是qq号",
user="注册账号",
password="",
project="head",
key="在后台修改配置的key"
}
-- key 看是否在个人后台开启,如开启在postdata中添加参数即可
-- 无文件上传的接口,filedata参数传nil即可
filedata={
head="/storage/emulated/0/Pictures/Image.jpg" -- 头像图片的路径
}
shuixian.api("user","user_set",postdata,filedata,function(code,content,cookie,header)
if(code==200) then
local result=cjson.decode(content)
if(result.code==1) then
print("修改成功") -- 编写自己的业务处理代码
elseif(result.code==0) then
print("修改失败-"..result.msg) -- 编写自己的业务处理代码
else
print("程序错误-"..result.msg) -- 编写自己的业务处理代码
end
else
end
end)
--[[
返回参数的多层级的json,如举报记录接口,查看文档返回如下参数:
返回参数{
code=响应码(0失败,1成功,-1程序错误)
msg=响应信息
data{
id=id
user=举报用户
name=用户昵称
head=用户头像
content=举报内容
time=举报时间
state=受理状态
result=受理内容
}
}
如:
获取举报用户,result.data.user即可
]]
对接返回json格式数据的api,就是一个json解析的操作,通过软件自带的网络请求模块即可完成我们的需求。
本文由【产品经理不是经理】gzh同步发布,欢迎关注
我是ruby的新手,我认为重新构建一个我用C#编写的简单聊天程序是个好主意。我正在使用Ruby2.0.0MRI(Matz的Ruby实现)。问题是我想在服务器运行时为简单的服务器命令提供I/O。这是从示例中获取的服务器。我添加了使用gets()获取输入的命令方法。我希望此方法在后台作为线程运行,但该线程正在阻塞另一个线程。require'socket'#Getsocketsfromstdlibserver=TCPServer.open(2000)#Sockettolistenonport2000defcommandsx=1whilex==1exitProgram=gets.chomp
我已经按照https://github.com/wayneeseguin/rvm#installation上的说明通过RVM安装了Ruby.有关信息,我有所有文件(readline-5.2.tar.gz、readline-6.2.tar.gz、ruby-1.9.3-p327.tar.bz2、rubygems-1.8.24.tgz、wayneeseguin-rvm-stable.tgz和yaml-0.1.4.tar.gz)在~/.rvm/archives目录中,我不想在任何目录中重新下载它们方式。当我这样做时:sudo/usr/bin/apt-getinstallbuild-essent
我的Ruby-on-Rails项目中有以下文件结构,用于规范:/spec/msd/serviceservice_spec.rb/support/my_modulerequests_stubs.rb我的request_stubs.rb有:moduleMyModule::RequestsStubsmodule_functiondeflist_clientsurl="dummysite.com/clients"stub_request(:get,url).to_return(status:200,body:"clientsbody")endend在我的service_spec.rb我有:re
Ruby是否支持(找不到更好的词)非转义(逐字)字符串?就像在C#中一样:@"c:\ProgramFiles\"...或者在Tcl中:{c:\ProgramFiles\} 最佳答案 是的,您需要在字符串前加上%前缀,然后是描述其类型的单个字符。你想要的是%q{c:\programfiles\}。镐书很好地涵盖了这一点here,部分是通用分隔输入。 关于ruby-Ruby是否支持逐字字符串?,我们在StackOverflow上找到一个类似的问题: https:/
我正在编写一个Rubygem,在我的代码中使用{key:'value'}哈希语法。我的测试都在1.9.x中通过,但我(可以理解)在1.8.7中得到syntaxerror,unexpected':',expecting')'。是否有支持1.8.x的最佳实践?我是否需要使用我们的老friend=>重写代码,还是有更好的策略? 最佳答案 我认为你运气不好,如果你想支持1.8,那么你必须使用=>。像往常一样,我会提到在1.9的某些情况下您必须使用=>:如果键不是一个符号。请记住,任何对象(符号、字符串、类、float……)都可以是Ruby哈
在Rails中,什么是集成更新模型某些元素的UDP监听过程的最佳方式(特别是它将向其中一个表添加行)。简单的答案似乎是在同一个进程中使用UDP套接字对象启动一个线程,但我什至不清楚我应该在哪里做适合Rails方式的事情。有没有一种巧妙的方法来开始收听UDP?具体来说,我希望能够编写一个UDPController并在每个数据报消息上调用一个特定的方法。理想情况下,我希望避免在UDP上使用HTTP(因为它会浪费一些在这种情况下非常宝贵的空间),但我完全控制消息格式,因此我可以为Rails提供它需要的任何信息。 最佳答案 Rails是一个
我想知道使用fork{}从Rails应用程序“后台”处理是否是个好主意...从我收集到的fork{my_method;Process#setsid}实际上做了它应该做的事情。1)创建另一个具有不同PID的进程2)不中断调用过程(例如它继续w/o等待fork完成)3)执行子进程直到它完成..这很酷,但这是个好主意吗?fork到底在做什么?它会在内存中创建我的整个railsmongrel/passenger实例的重复实例吗?如果是这样那就太糟糕了。或者,它是否以某种方式在不消耗大量内存的情况下完成。我的最终目标是取消我的后台守护进程/队列系统,转而支持这些进程的fork(主要是发送电子邮件
我是Ruby和Watir-Webdriver的新手。我有一套用VBScript编写的站点自动化程序,我想将其转换为Ruby/Watir,因为我现在必须支持Firefox。我发现我真的很喜欢Ruby,而且我正在研究Watir,但我已经花了一周时间试图让Webdriver显示我的登录屏幕。该站点以带有“我同意”区域的“警告屏幕”开头。用户点击我同意并显示登录屏幕。我需要单击该区域以显示登录屏幕(这是同一页面,实际上是一个表单,只是隐藏了)。我整天都在用VBScript这样做:objExplorer.Document.GetElementsByTagName("area")(0).click
我收到错误:unsupportedcipheralgorithm(AES-256-GCM)(RuntimeError)但我似乎具备所有要求:ruby版本:$ruby--versionruby2.1.2p95OpenSSL会列出gcm:$opensslenc-help2>&1|grepgcm-aes-128-ecb-aes-128-gcm-aes-128-ofb-aes-192-ecb-aes-192-gcm-aes-192-ofb-aes-256-ecb-aes-256-gcm-aes-256-ofbRuby解释器:$irb2.1.2:001>require'openssl';puts
我刚找到thiscomment来自mojombo:ThelatestonmasternowhasPluginsupport.Lookatlib/jekyll/convertersforexamplesofhowthey'redone.Also,any*.rbfilesina_pluginsdirectorywillbeloadedsothatyoucancreatecustompluginsofyourown.我看过/lib/jekyll/converters但无法理解它们应该如何工作。谁能给我解释一下?非常感谢。 最佳答案 一个新