MCPcopy
hub / github.com/gongjunhao/seckill / getServerTimeAndUpdate

Function getServerTimeAndUpdate

src/js/utils.js:158–192  ·  view source on GitHub ↗

* 获取北京时间

()

Source from the content-addressed store, hash-verified

156 * 获取北京时间
157 */
158function getServerTimeAndUpdate() {
159 //北京时间接口路径
160 var apiUrl = "https://sapi.k780.com/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json&jsoncallback=data";
161
162 //调用接口获取北京时间
163 var startTime = new Date().getTime();
164 $.ajax({
165 type : 'get',
166 async : false,
167 url : apiUrl,
168 dataType : 'jsonp',
169 jsonp : 'callback',
170 jsonpCallback : 'data',
171 success : function(data){
172 if(data.success!='1'){
173 console.error(data.msgid+' '+data.msg);
174 console.error("调用接口获取北京时间失败!使用本机时间");
175 updateTime(new Date().getTime()+fastTime);
176 }
177 for(var i in data.result){
178 var property=data.result[i];
179 if(i == "timestamp") {
180 standerTime = parseInt(property+"000");
181 var diff = (new Date().getTime() - startTime)/2;
182 standerTime += (diff + 500);
183 updateTime(standerTime);
184 }
185 }
186 },
187 error:function(){
188 console.error("调用接口获取北京时间失败!使用本机时间");
189 updateTime(new Date().getTime()+fastTime);
190 }
191 });
192}
193
194/**
195 * 更新popup page的北京时间,剩余时间和设定后台的时间

Callers 1

utils.jsFile · 0.85

Calls 1

updateTimeFunction · 0.85

Tested by

no test coverage detected