权朗网络API3.0

权朗网络API3.0


函数库

<pre><code class="language-lua">function request(api,param) center_id = &amp;quot;xxxx&amp;quot;;--[===[这个是开发者id,在权朗网络网站上或者app里都能看到,5位数]===] api_password = &amp;quot;xxxxxx&amp;quot;;--[===[这个是api密码,在权朗后台或者app的设置里面能看到]===] client_key = getDeviceId();--[===[这里是防破解专用的,这里默认是取了设备ID,如果觉得这个不靠谱可以被伪造,那么可以自行修改这个方法,只要能获取到设备的一个唯一标识就可以]===] net_reconnect_times = 30;--[===[这里是网络连接失败的重连次数,一般不用动。如果大批量用户经常出现连接服务器失败,那么可以把这个数值加大]===] timestamp = get_net_timestamp(0);--[===[这一行代码的意思是获取网络时间戳,如果淘宝的你觉得不适用,那么可以自行写一个函数去获取时间戳,不管是用什么网络时间戳或者本地方法,只要能获取到当前的时间戳就行]===] --[===[以下内容一般不要动,涉及加密算法,看不懂不要轻易动]===] api_list = {&amp;quot;https://napi.2cccc.cc/&amp;quot;,&amp;quot;http://api2.2cccc.cc/&amp;quot;,&amp;quot;http://api3.2cccc.cc/&amp;quot;};--[===[这里是服务器列表,如果你没有开独立服务器,那么不用动这里]===] client_key = MD5( api_password .. client_key .. timestamp ); api_password = api_password .. client_key; sign = MD5(api_password .. timestamp); common_params = &amp;quot;center_id=&amp;quot; .. center_id .. &amp;quot;&amp;amp;tmstamp=&amp;quot; .. timestamp .. &amp;quot;&amp;amp;sign=&amp;quot; .. sign .. &amp;quot;&amp;amp;client_key=&amp;quot; .. client_key; connect_times = 0; response = &amp;quot;&amp;quot;; while( string.sub(response,3,6) ~= &amp;quot;code&amp;quot; ) do connect_times = connect_times + 1; host = api_list[ math.random(1, #api_list ) ]; response = httpPost(host .. api,common_params .. &amp;quot;&amp;amp;&amp;quot; .. param); if string.sub(response,3,6) ~= &amp;quot;code&amp;quot; then print(&amp;quot;连接登陆服务器失败,尝试重连&amp;quot;); sleep(10000); end if connect_times &amp;gt; net_reconnect_times then print(&amp;quot;连接登陆服务器失败,请检查您的网络&amp;quot;) exitScript() end end result = jsonLib.decode( response ); if result.code ~= &amp;quot;1&amp;quot; then return result; end if string.upper( result.sign ) ~= string.upper( MD5( string.sub(tostring(result.timestamp),0,10) .. api_password ) ) or math.abs(result.timestamp - timestamp) &amp;gt; 600 then table = {} table[&amp;quot;code&amp;quot;] = &amp;quot;0&amp;quot;; table[&amp;quot;msg&amp;quot;] = &amp;quot;验证签名错误,请检查api密码是否正确&amp;quot;; return table end return result; end --[===[这里是获取网络时间戳的函数,使用的是淘宝,如果你觉得淘宝的不靠谱或者不适用,那么自行修改这个函数即可,只要返回值是当前10位数实时时间戳就行,用什么方法都可以]===] function get_net_timestamp(times) if times == 0 then timestamp_json = httpGet(&amp;quot;https://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp&amp;quot;); if string.sub(timestamp_json,0,2) == &amp;#039;{&amp;quot;&amp;#039; then print(&amp;quot;获取淘宝时间戳成功&amp;quot;) timestamp_table = jsonLib.decode(timestamp_json); return string.sub(timestamp_table.data.t,0,10); else print(&amp;quot;获取淘宝时间戳失败,开始获取拼多多时间戳&amp;quot;) return get_net_timestamp(times+1) end end if times == 1 then timestamp_json = httpGet(&amp;quot;https://api.pinduoduo.com/api/server/_stm&amp;quot;); if string.sub(timestamp_json,0,2) == &amp;#039;{&amp;quot;&amp;#039; then print(&amp;quot;获取拼多多时间戳成功&amp;quot;) timestamp_table = jsonLib.decode(timestamp_json); return string.sub(timestamp_table.server_time,0,10); else print(&amp;quot;获取拼多多时间戳失败,开始获取世界时间戳&amp;quot;) return get_net_timestamp(times+1) end end if times == 2 then timestamp_json = httpGet(&amp;quot;https://worldtimeapi.org/api/timezone/Asia/Shanghai&amp;quot;); if string.sub(timestamp_json,0,2) == &amp;#039;{&amp;quot;&amp;#039; then print(&amp;quot;获取世界时间戳成功&amp;quot;) timestamp_table = jsonLib.decode(timestamp_json); return string.sub(timestamp_table.unixtime,0,10); else print(&amp;quot;获取世界时间戳失败,开始获取本地时间戳&amp;quot;) return get_net_timestamp(times+1) end end if times == 3 then print(&amp;quot;获取本地时间戳&amp;quot;) return os.time() end taobao_timestamp_json = &amp;quot;&amp;quot;; connect_times = 0; while(string.sub(taobao_timestamp_json,3,5) ~= &amp;quot;api&amp;quot;) do connect_times = connect_times + 1 taobao_timestamp_json = httpGet(&amp;quot;https://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp&amp;quot;); if string.sub(taobao_timestamp_json,3,5) ~= &amp;quot;api&amp;quot; then print(&amp;quot;连接淘宝时间服务器失败,尝试重连&amp;quot;); sleep(6000); end if connect_times &amp;gt; 10 then print(&amp;quot;连接淘宝时间服务器失败,请检查您的网络&amp;quot;) exitScript() end end taobao_timestamp_table = jsonLib.decode(taobao_timestamp_json); return string.sub(taobao_timestamp_table.data.t,0,10); end </code></pre>

页面列表

ITEM_HTML