order.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. $("#productSelect").change(function() {
  2. // 联通在线定向流量集约平台-畅视
  3. // system_id : 39
  4. // sourcedevice_id:390001
  5. // sourcedevice_name:联通在线定向流量集约平台
  6. // client_id : n3acdDxpFQ1aDDE1FhKr
  7. // client_secret : SaREX72YV46luwvLx1M3
  8. //
  9. // 联通在线定向流量集约平台-沃音乐
  10. // system_id : 40
  11. // sourcedevice_id:400001
  12. // sourcedevice_name:联通在线定向流量集约平台
  13. // client_id: kqpH3U4Y9QpRkORW6l9k
  14. // client_secret : p0QUs7bhpjkmWnXSBWr2
  15. //
  16. // 联通在线定向流量集约平台-小沃科技
  17. // system_id : 41
  18. // sourcedevice_id:410001
  19. // sourcedevice_name:联通在线定向流量集约平台
  20. // client_id : Wjb0RKxO8OsCqr1UDTna
  21. // client_secret : 'bVTdjATcc9HhyWR28J81
  22. //
  23. // 联通在线定向流量集约平台-沃悦读
  24. // system_id : 42
  25. // sourcedevice_id:420001
  26. // sourcedevice_name:联通在线定向流量集约平台
  27. // client_id : U1UcIFZAAeX1gV4VGPe2
  28. // client_secret : siF6V1jCTWPZNyqYlb1G
  29. // 联通在线定向流量集约平台-沃悦读
  30. // system_id: ,
  31. // "SOURCEDEVICE_ID":"650000"
  32. const params = {
  33. "SPID": $("#productSelect").find("option:selected").attr('spid'),
  34. "PRODUCT_ID": $("#productSelect").find("option:selected").attr('prmproductid'),
  35. "PRODUCT_NAME": $("#productSelect").find("option:selected").attr('productname'),
  36. "PRODUCT_PRICE": $("#productSelect").find("option:selected").attr('productprice'),
  37. "PRODUCT_TYPE": $("#productSelect").find("option:selected").attr('producttype')
  38. };
  39. $('#product').text(JSON.stringify(params))
  40. })
  41. $('#btn-order').unbind('click').on('click', function() {
  42. $("#btn-order").attr('disabled', true);
  43. $("body").css("overflow", "hidden");
  44. let capUrl = $('#evnSelect').find("option:selected").attr('capurl');
  45. // var $iframe = $('<iframe id="uniauthframe" src="https://cap.chinaunicom.cn/CAP-AUTH/"></iframe>')
  46. var $iframe = $('<iframe id="uniauthframe" src="'+capUrl+'"></iframe>')
  47. // var $iframe = $('<iframe id="uniauthframe" src="http://cap.free.svipss.top/cap_auc_frontpage/webapp/auth-dx.html"></iframe>')
  48. var targetOrigin = "";
  49. if (capUrl.indexOf("https://cap.chinaunicom.cn") >= 0) {
  50. targetOrigin = "https://cap.chinaunicom.cn/";
  51. } else if (capUrl.indexOf("http://cap.free.svipss.top") >= 0) {
  52. targetOrigin = "http://cap.free.svipss.top/"
  53. } else if (capUrl.indexOf("https://captain.chinaunicom.cn")) {
  54. targetOrigin = "https://captain.chinaunicom.cn/"
  55. }
  56. var PRODUCT_NAME = $("#productSelect").find("option:selected").attr('productname');
  57. var PRODUCT_PRICE = $("#productSelect").find("option:selected").attr('productprice');
  58. var PRODUCT_ID = $("#productSelect").find("option:selected").attr('prmproductid');
  59. var PRODUCT_TYPE = $("#productSelect").find("option:selected").attr('producttype');
  60. var SPID = $("#productSelect").find("option:selected").attr('spid');
  61. var params = {
  62. "PRODUCT_NAME": PRODUCT_NAME,
  63. "PRODUCT_PRICE": PRODUCT_PRICE,
  64. "CLIENT_ID": "",
  65. "CLIENT": "3",
  66. "SERVICE_ID": "",
  67. "AUTH_NO": "",
  68. "CLIENT_SECRET": "",
  69. "VERSION": "1.0",
  70. "SERVICE_PHONE": "",
  71. "THEME": "",
  72. "PRODUCT_ID": PRODUCT_ID,
  73. "PRODUCT_TYPE": PRODUCT_TYPE
  74. }
  75. $iframe.on('load', function() {
  76. $.ajax({
  77. //请求后项定向服务获取
  78. url: getRootPath() + "-s1api" + "/ini/clientsecret?spid=" + SPID,
  79. dataType: "JSON",
  80. method: "GET",
  81. success: function(data) {
  82. params.CLIENT_ID = data.client_id;
  83. params.AUTH_NO = data.auth_no;
  84. params.CLIENT_SECRET = data.client_secret;
  85. console.log(params)
  86. $('#uniauthframe')[0].contentWindow.postMessage(
  87. JSON.stringify(params), targetOrigin)
  88. }
  89. })
  90. })
  91. $('body').append($iframe);
  92. //监听统一认证结果
  93. window.addEventListener('message', function(e) {
  94. let data = JSON.parse(e.data);
  95. $('#token').text(e.data)
  96. switch (data.RSP.RSP_CODE) {
  97. case "0000": //处理成功
  98. $('iframe').remove();
  99. break;
  100. case "0001": //auth_no无效 (入参流水)
  101. alert("认证失败!");
  102. break;
  103. case "0003": //client_id不存在 (注册id存在问题)
  104. alert("认证失败!");
  105. break;
  106. case "4444": //服务暂时不可用(系统忙/系统队列满)
  107. alert("服务暂时不可用!");
  108. break;
  109. case "9001": //关闭H5认证页面
  110. $('iframe').remove();
  111. break;
  112. }
  113. }, false);
  114. })
  115. /*
  116. 获取root
  117. */
  118. function getRootPath() {
  119. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  120. var curWwwPath = window.document.location.href;
  121. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  122. var pathName = window.document.location.pathname;
  123. var pos = curWwwPath.indexOf(pathName);
  124. //获取主机地址,如: http://localhost:8080
  125. var localhostPath = curWwwPath.substring(0, pos);
  126. //获取带"/"的项目名,如:/ems
  127. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  128. root = (localhostPath + projectName);
  129. return (localhostPath + projectName);
  130. }