sample.js 862 B

1234567891011121314151617181920212223242526272829303132333435
  1. // 输入输出参数格式化
  2. input = INPUT;
  3. output = {};
  4. try {
  5. input = decodeURIComponent(input);
  6. } catch (e) { }
  7. try {
  8. input = base64.decode(input);
  9. } catch (e) { }
  10. try {
  11. input = JSON.parse(input);
  12. input = JSON.parse(input); // 解析可能存在的重复编码
  13. } catch (e) { }
  14. // 主执行阶段
  15. try {
  16. // 示例处理过程,返回输入信息
  17. output.sampledata = {
  18. input: input,
  19. };
  20. } catch (e) {
  21. // 错误信息输出处理,抛出 ok 表示正常结束
  22. if (e != "ok") {
  23. if (typeof (e) == "object") {
  24. output.error = e;
  25. } else if (typeof (e) == "string") {
  26. output.error = "错误:" + e;
  27. } else {
  28. output.error = JSON.stringify(e);
  29. }
  30. log.error(output.error);
  31. STATUS = "error";
  32. }
  33. }
  34. // 返回输出信息
  35. OUTPUT = output;