Skip to content
高海 edited this page Jun 19, 2015 · 11 revisions

API接口简介

接口参数参数属性 请查看相应的接口 URL,所有接口为方便调试,都为GET请求,JSONP接口(callback参数请自行设置),暂无sign验证逻辑。

部分接口有分页,分页约定:

请求参数

p 		: 页面序号,如 p=1 查看第一页
size 	: 页面数据量条数,默认 size=20 条

返回码

page: {
		currentp: 1, 	//当前页面序号
		size: 20, 		//每页信息条数
		allnews: 1,		//总信息条数
		pageCount: 1 	//总页面量
	},

一,获取广域网IP

注: 获取广域网接口也可以调用 http://pv.sohu.com/cityjson (GET,JsonP)请求参数:无

GET示例:

http://192.168.31.248:4000/getip?callback=a

返回:

a({
    code: 2000, 			//返回码
    message: "success", 	//返回码解释
    data: "122.224.65.226" 	//查询结果公网ip
})

二,报名信息填写

(GET,JsonP)请求参数:

name 		: String 宝贝姓名
wx_nick 	: String 微信昵称
wx_id 		: String 微信 id
password 	: String 密码(该业务 可以省略)
sex 		: Num 性别;0:未知 1:男 2:女
age 		: Num 年龄(单位月份)
tel 		: String 电话
email 		: String 邮箱
photo		: String 上传照片url  JSON.stringify
content 	: String 宣言
ip 			: String 广域网ip

注1:业务要求用户不能改自己的信息(联系客服),so,password可为空 注2:请求之前需要进行 字段唯一性校验 见接口三 ,前端页面举例: http://jk.idacker.com:3000/register

GET示例:

http://localhost:4000/adduser?name=test111&wx_nick=highsea90&wx_id=gh123456&password=123456&sex=1&age=5&tel=15161789856&email=admin@highsea90.com&photo=[%22http://a.com%22,%20%22http://b.com%22]&content=ceshi&ip=192.168.1.244

返回:

{
	code: 2000,
	message: "success",
	data: {
		fieldCount: 0,
		affectedRows: 1,
		insertId: 14,
		serverStatus: 2,
		warningCount: 0,
		message: "",
		protocol41: true, //插入成功
		changedRows: 0
	}
}

三,字段唯一性校验

(GET,JsonP)如: 注:宝贝姓名(name),电话(tel),邮箱(email)唯一,在提交报名请求前(前端进行校验, 见接口三 ,前端页面举例: http://jk.idacker.com:3000/register

请求参数:

type : name | tel | email
value: String 相应的值

GET示例:

http://localhost:4000/userCount?type=name&value=test111

返回:

{
	code: 2000,
	message: "success",
	data: 1 //有一条数据,表明数据库已有相同数据
}

四,微信相关接口

注,appid 和 secretid 为后台默认设置

为 SDK开发的 access_token 和 ticket 以及 sha1加密

access_token:

http://xiaojiaoyar.com:3000/weixin?type=access_token

ticket:

http://xiaojiaoyar.com:3000/weixin?type=ticket

sha1:

http://xiaojiaoyar.com:3000/sha1?ticket=abc&url=http://highsea90.com
为 Auth 认证开发
  1. 获取 code 举例 url如下:(其中 appid,redirect_uri,response_type,scope,state,connect_redirect相关参数配置 请移步这里: 网页授权获取用户基本信息

    https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx65deb1c87416d0b7&redirect_uri=http://wechat.highsea90.com/wx.html&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect

  2. 获取 授权登录的 access_token 不同于 sdk 基础支持中的 token GET示例:

    http://192.168.31.248:4000/wx_auth_token?code=0313d240786f8c4cda3b1779f05c248x

  3. 获取 授权登录的 refresh_token 如有需要

GET示例:

http://192.168.31.248:4000/wx_refresh_token?token=123
  1. 获取 微信个人信息

GET示例:

http://192.168.31.248:4000/wx_userinfo?openid=123&token=456
  1. demo(用的测试账号 可能会过期)

    http://wechat.highsea90.com/wx-auth-demo.html

  2. 图例:

授权页面1 授权页面2 授权页面3

五,图片上传

注1. 上传文件格式判断(后端接口虽然有判断,但是上传前前端也要判断),仅允许图片格式,如:jpg,jpeg,png,gif,x-png 注2. 此上传接口为 post 但为方便前端调试 该接口已经设置成 web页面,如有需要可以用方式1

方式1: (post 接口实现)

http://localhost:4000/postpic

form 表单实现,如:

<form method="post" action="http://localhost:4000/postpic" enctype="multipart/form-data" onsubmit="return check();">
	<input type="file" name="files" multiple="multiple" />
	<input type="submit" class="btn btn-success" value="上传" />
</form>

返回:

{
	code: 2000,
	message: "success",
	data: "1434437740.png" //返回上传的图片名称,完整路径为 host/upload/temp/ 见下
}

查看图片:

http://localhost:4000/upload/temp/1434437740.png

方式2: (iframe方式实现)

调用页面:(附上 username 参数,即需要知道谁上传了垃圾)

http://localhost:4000/upload?username=highsea

嵌入页面 iframe 方式快速调用:

<iframe id="upiframe" src="/upload?username={{username}}" frameborder="0" height="65" scrolling="no" ></iframe>

获取子iframe页面img链接属性src:

var upi = window.top.document.getElementById("upiframe").contentWindow,
    picurl = upi.document.getElementsByTagName('img')[0]==undefined ? '' : upi.document.getElementsByTagName('img')[0].getAttribute('src');

关于UI以及交互

UI: 被调用的 iframe 已经引入与前端约定的远程 css文件 交互: 默认选择完成文件后自动上传文件

六,报名信息查询

请求参数说明:

order 	: 排序方式,支持-votenum(票数多少)-time(注册时间)-age(宝贝年龄)
sta 	: 状态,支持-all(所有状态的用户,level!='')-ready(正常使用的用户,level=1)-del(被禁用的用户,level=0)-admin(管理员,level=8)

GET示例:

目前业务需求,如查询所有 正常使用 的用户按 注册时间排序 (默认分页数据量每页10条):

http://localhost:4000/userinfo?order=time&sta=ready&p=1&size=10

返回:

{
	code: 2000,
	message: "success",
	data: {
		len: 10,	
		page: {					//当前页面信息长度
			currentp: "1", 		//当前页面序号
			size: "10", 		//每页信息条数
			allnews: 11,		//总信息条数
			pageCount: 2 		//总页面量
			},
		list: [
			{
			id: "1",		 	//id
			name: "test", 		//名称
			sex: 0, 			//性别;0:未知 1:男 2:女
			age: 13,			//年龄 这里指月份
			tel: "151515151566",//电话号
			wx_nick: "null", 	//微信昵称
			email: "", 			//邮箱
			wx_id: "null", 		//微信id
			…… 以下省略 ……

七,用户名模糊查询

暂不支持智能查询,检索如: a+b 或者 a b (GET,JsonP)请求参数:

value : String 要查询的值

GET示例:

http://localhost:4000/lookuser?value=g&p=1&size=20

返回:

{
	code: 2000,
	message: "success",
	data: {
		len: 1, 			//当前页面信息长度
		page: {
			currentp: 1, 	//当前页面序号
			size: 20, 		//每页信息条数
			allnews: 1,		//总信息条数
			pageCount: 1 	//总页面量
		},
		list: [
			{
				id: 4, 				//宝贝id
				name: "hi-blog", 	//名称
				sex: 0, 			//性别;0:未知 1:男 2:女
				age: 3,				//年龄 这里指月份
				tel: "12345678908", //电话号
				wx_nick: "null", 	//微信昵称
				email: "", 			//邮箱
				wx_id: "null", 		//微信id
				photo: null, 		//照片
				content: "123456", 	//宣言
				vote_num: 1, 		//票数
				ip_reg: "192.168.1.4", //注册ip
				ctime: 1434436567,	//注册时间
				level: 1 			//用户状态 1:正常;2:禁用;8:管理员
			}
		]
	}
}

八,个人主页查询

(GET,JsonP)参数介绍:

id : 宝贝id

GET示例:

http://localhost:4000/onebaby?id=4

返回:

{
	code: 2000,
	message: "success",
	data: [
		{
			id: 4, 				//宝贝id
			name: "hi-blog", 	//名称
			sex: 0, 			//性别;0:未知 1:男 2:女
			age: 3,				//年龄 这里指月份
			tel: "12345678908", //电话号
			wx_nick: "null", 	//微信昵称
			email: "", 			//邮箱
			wx_id: "null", 		//微信id
			photo: null, 		//照片
			content: "123456", 	//宣言
			vote_num: 1, 		//票数
			ip_reg: "192.168.1.4", //注册ip
			ctime: 1434436567 	//注册时间
			level: 1 			//用户状态 1:正常;2:禁用;8:管理员
		}
	]
}

九,在线投票API

(GET,JsonP)参数介绍:

ip 		: 投票ip
babyid 	: 投给那个baby

GET示例:

http://localhost:4000/govote?babyid=20&ip=10.2.3.56&wxid=24sada

返回:

{
	code: 2000,
	message: "success",
	data: {
		fieldCount: 0,
		affectedRows: 1,
		insertId: 0,
		serverStatus: 2,
		warningCount: 0,
		message: "(Rows matched: 1 Changed: 1 Warnings: 0",
		protocol41: true,
		changedRows: 1
	}
}

防止刷票机制:

每天10次,间隔24小时算,而不是0点刷新

{
	code: 1028,
	message: "每天,您的投票次数(10次)已经用完了~",
	data: null
}

每天每个投票id(微信openid)只能投某个宝贝(babyid)最多3次

{
	code: 1029,
	message: "每天,每个宝贝只能接受您3票",
	data: null
}

其他数据API

十,页面 PV 写入

(GET,JsonP)参数介绍:

ip 		: 客户端公网ip
pageid 	: 页面埋点id

GET示例:

http://localhost:4000/cpv?ip=8.8.8.8&pageid=100009

返回:

{
	code: 2000,
	message: "success",
	data:{
		fieldCount: 0,
		affectedRows: 1,
		insertId: 8,
		serverStatus: 2,
		warningCount: 0,
		message: "",
		protocol41: true,
		changedRows: 0
	}
}

十一,某个页面的 PV 查询

(GET,JsonP)参数介绍:

pageid : 页面埋点id

GET示例:

http://localhost:4000/spv?pageid=100001

返回:

{
	code: 2000,
	message: "success",
	data: 4
}

十二,总报名人数以及总投票数查询

(GET,JsonP)参数介绍:

GET示例:

http://localhost:4000/sbabyvote

返回:

{
	code: 2000,
	message: "success",
	data:{
		registerNum: 14,
		vote: 23
	}
}