Recientemente, quiero desarrollar un gadget para compras de pánico. Necesito sincronizar la hora del sistema. Aquí comparto dos API de interfaz de servidor de hora para todos:
1. Interfaz de tiempo del servidor horario de Taobao
http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp
Devolver datos json
{"api": "mtop.common.getTimestamp", "v": "*", "ret": ["ÉXITO :: 接口 调用 成功"], "data": {"t": "1586519130440"}}
Python obtiene el ejemplo de la hora del servidor horario de Taobao
1 importación solicitudes 2 importación de tiempo 3 4 clase timeTaobao (objeto): 5 r1 = requests.get (url = ' http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp ' , 6 encabezados = { ' User-Agent ' : ' Mozilla / 5.0 (Windows NT 10.0; WOW64) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome / 55.0.2883.87 UBrowser / 6.2.4098.3 Safari / 537.36 ' }) 7 x = eval (r1.text) 8 timeNum = int (x [ ' data ' ] [' t ' ]) 9 10 def funcname (): 11 timeStamp = float (timeTaobao.timeNum / 1000 ) 12 timeArray = time.localtime (timeStamp) 13 otherStyleTime = time.strftime ( " % Y-% m-% d% H :% M:% S " , timeArray) 14 return otherStyleTime 15 16 t = timeTaobao.funcname () 17 print (t)
2. Interfaz del servidor de Suning Time API:
http://quan.suning.com/getSysTime.do
Devolver datos json
{"sysTime2": "2020-04-10 19:46:50", "sysTime1": "20200410194650"}