登录

在这个站点登录

保存我的登录记录

<<忘记密码?

还没有账号?点此注册>>

Jerry

百度在线输入法API用于PHP拼音转中文

分享到:

本文已被浏览6396

今天研究了下百度的在线输入法,研究其中的工作原理.

期初,我下载了他提供的API的那个JavaScript文件,经过分析,发现那货写的跟压缩版JQ似的,于是我放弃了从这里寻找突破口.随后,我又用FireFox的网络监控(F12->网络那个),发现每当输入一个字符,将会与百度的一个地址(http://olime.baidu.com/py)进行通信,并且其中包含一个参数,为刚刚已经输入并未选择备选的拼音.

http://olime.baidu.com/py
参数:
@input=拼音项目
@inputtype=py 这个地方写py应该是拼音的意思
@bg=0 暂时不清楚什么鬼
@ed=20 暂时不清楚什么鬼
@result=hanzi 暂时不清楚什么鬼
@resultcoding=utf-8 字符编码,当前试出来的有utf-8和Unicode
@ch_en=0  暂时不清楚什么鬼,可能有跟英文备选相关的东西
@clientinfo=web 肯定的要web,其他client可能会有桌面的
@version=1 没试过其他的

对这个进行请求,返回值为一个json值,其中包含了前几个字符的备选以及消耗的字符数量.下面是一个返回实例

{
	"status": "T",
	"errno": "0",
	"errmsg": "",
	"result": [[["呵呵",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["鹤鹤",4,{
		"pinyin": "he'he",
		"type": "NEWWORD"
	}],
	["赫贺",4,{
		"pinyin": "he'he",
		"type": "NEWWORD"
	}],
	["赫赫",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["和合",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["和和",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["喝喝",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["合合",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["嗬嗬",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["合和",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["荷荷",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["禾禾",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["何和",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["河合",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["鹤和",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["何何",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["呵喝",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["鹤贺",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["嗃嗃",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}],
	["翯翯",4,{
		"pinyin": "he'he",
		"type": "IMEDICT"
	}]],
	"he'he"]
}
Template:
{
	"status": "T",
	"errno": "0",
	"errmsg": "",
	"result": [[["备选词",消耗字符数量,{
		"pinyin": "对应拼音",
		"type": "来源"
	}]
	"拼音分词"]
}
 手机扫描左边的二维码,立刻将文章收入手机!
 微信扫描左边二维码,点击右上角即可分享到朋友圈!
严禁任何非授权的采集与转载,转载须经站长同意并在文章显著位置标注本文连接,站长保留追究法律责任的权利.

评论

 您需要 先登录 才可以回复.