一、前端
Vue.prototype.getSign = function(data) { var APITOKEN = 'api2021', timestamp = new Date().getTime(); return 'timestamp=' + timestamp + '&sign=' + md5(timestamp + APITOKEN); }
使用uni-app开发,请求接口地址携带上面生成的参数
二、后端
function checkApi() { global $sign, $timestamp; //验证接口 if ($sign != md5($timestamp . APITOKEN) || time() - substr($timestamp, 0, 10) > 60) { die(json_encode(['code' => -1, 'msg' => '接口验证错误!'])); } return true; }