UNPKG

thinkraz-api-sdk

Version:

橡芮科技API开发包

203 lines (202 loc) 7.94 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script> </head> <body> <div id="start_area"> <a href="javascript:TimescardPrototypeTemplate('create')">创建次卡模板</a> <a href="javascript:TimescardPrototypeTemplate('update')">更新次卡模板</a> <a href="javascript:changePrototypeForTimescard()">给次卡更改权限模板</a> <a href="javascript:getPrototypes()">获取模板列表</a> <a href="javascript:checkSportAndDiscount()">查询运动权限</a> <a href="javascript:getTimescardData()">查询次卡信息</a> <label>场馆id:</label><input id="gym_input" value="101440810"> </div> <div id="operation_area_1" hidden> <label for="name_input">模板名称</label><input id="name_input" value="测试模板"> <label for="name_input">模板注释</label><input id="desc_input" value="模板注释"> </div> <div id="operation_area_2" hidden> <label for="tid">次卡id</label><input id="tid" value="328903655180195392"> <label for="pro">模板id数组</label><input id="pro" width="800"> <a href="javascript:addPrototypeConfirm()">授权</a> </div> <div id="operation_area_3" hidden> <label for="pid">模板id</label><input id="pid" value="325182911505289645620"> </div> <div id="operation_area_4" hidden> <label for="tid2">次卡id</label><input id="tid2" value="328903655180195392"> <label for="sporttype">运动类型</label><input id="sporttype" value="YUMAOQIU"> <a href="javascript:checkValidate()">查询</a> </div> <div id="operation_area_5" hidden> <label for="tid3">次卡id</label><input id="tid3" value="328903655180195392"> <a href="javascript:checkValidate()">查询</a> </div> <div id="response"></div> <script> const mchid = '101464'; const mchkey = '8cc9-7ad5-7d19-d903'; const baseGymUrl = 'http://gym.api.bolopie.thinkraz.com/'; const baseTimescardUrl = 'http://timescard.api.bolopie.thinkraz.com/'; function addLog(str) { document.getElementById('response').innerHTML += str + '<br>'; } function post(url, data, cb) { $.ajax({ url: url, type: 'POST', data: data, success: function (result) { cb(result); }, error: function (err) { alert('Failed!'); addLog('============' + url + '连接失败!==============='); } }); } function get(url, data, cb) { $.ajax({ url: url, type: 'GET', data: data, success: function (result) { cb(result); }, error: function (err) { console.log('err', err); // alert('Failed!'); // addLog('============' + url + '连接失败!==============='); cb(err); } }); } var addSport = null; var confirmNext = null; var addPrototypeConfirm = null; var updateTemplate = null; var checkValidate = null; function checkSportAndDiscount() { $('#start_area').hide(); $('#operation_area_4').show(); checkValidate = function () { get(baseTimescardUrl + 'validate', { tid: $('#tid2').val(), mchid: mchid, auth: $('#sporttype').val(), }, function (result) { addLog('已完成:获取回调信息:' + JSON.stringify(result)); addLog('============================================'); }) }; } function getTimescardData() { $('#start_area').hide(); $('#operation_area_5').show(); checkValidate = function () { get(baseTimescardUrl + 'timescard', { tid: $('#tid3').val(), mchid: mchid, prototype: true }, function (result) { addLog('已完成:获取回调信息:' + JSON.stringify(result)); addLog('============================================'); }) }; } function getPrototypes() { $('#start_area').hide(); get(baseTimescardUrl + 'prototype/template', { tid: $('#tid').val(), mchid: mchid }, function (result) { addLog('已完成:获取回调信息:' + JSON.stringify(result)); addLog('============================================'); }) } function changePrototypeForTimescard() { $('#start_area').hide(); $('#pro').val('["008973361505279207409"]'); $('#operation_area_2').show(); addPrototypeConfirm = function () { post(baseTimescardUrl + 'prototype', { mchid: mchid, mchkey: mchkey, tid: $('#tid').val(), prototypes: JSON.parse($('#pro').val()) }, step1); function step1(result) { addLog('已完成:获取回调信息:' + JSON.stringify(result)); addLog('============================================'); } } } function TimescardPrototypeTemplate(method) { $('#start_area').hide(); // step1: get gym sports var gym = $('#gym_input').val(); var sports = []; get(baseGymUrl + gym + '/sports', {}, function (result) { if (method == 'update') { $('#operation_area_3').show(); } else { $('#operation_area_1').show(); } addLog('第一步:获取场馆运动信息:' + JSON.stringify(result)); addLog('============================================'); var response = $('#response'); for (let i = 0; i < result.data.length; i++) { // result.data[i].code var a = $('<a>'); a.text(result.data[i].name); a.attr('href', `javascript:addSport('${result.data[i].code}')`); response.append(a); response.append($('<br>')); } var b = $('<a>'); b.text('完成'); b.attr('href', `javascript:confirmNext()`); response.append(b); response.append($('<br>')); }); addSport = function (code) { sports.push(code); addLog('已选择:' + JSON.stringify(code)); }; confirmNext = function () { var template = {}; for (let i = 0; i < sports.length; i++) { template[sports[i]] = {discount: 0}; } if (method == 'create') { post(baseTimescardUrl + 'prototype/template', { mchid: mchid, mchkey: mchkey, name: $('#name_input').val(), description: $('#desc_input').val(), template: template }, step2) } else if (method == 'update') { var pid = $('#pid').val(); post(baseTimescardUrl + 'prototype/template/' + pid, { mchid: mchid, mchkey: mchkey, name: $('#name_input').val(), description: $('#desc_input').val(), template: template }, step2) } else { addLog('SB'); } }; function step2(result) { addLog('第2步:获得结果:' + JSON.stringify(result)); addLog('============================================'); } } </script> </body> </html>