123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- $("#productSelect").change(function() {
- // 联通在线定向流量集约平台-畅视
- // system_id : 39
- // sourcedevice_id:390001
- // sourcedevice_name:联通在线定向流量集约平台
- // client_id : n3acdDxpFQ1aDDE1FhKr
- // client_secret : SaREX72YV46luwvLx1M3
- //
- // 联通在线定向流量集约平台-沃音乐
- // system_id : 40
- // sourcedevice_id:400001
- // sourcedevice_name:联通在线定向流量集约平台
- // client_id: kqpH3U4Y9QpRkORW6l9k
- // client_secret : p0QUs7bhpjkmWnXSBWr2
- //
- // 联通在线定向流量集约平台-小沃科技
- // system_id : 41
- // sourcedevice_id:410001
- // sourcedevice_name:联通在线定向流量集约平台
- // client_id : Wjb0RKxO8OsCqr1UDTna
- // client_secret : 'bVTdjATcc9HhyWR28J81
- //
- // 联通在线定向流量集约平台-沃悦读
- // system_id : 42
- // sourcedevice_id:420001
- // sourcedevice_name:联通在线定向流量集约平台
- // client_id : U1UcIFZAAeX1gV4VGPe2
- // client_secret : siF6V1jCTWPZNyqYlb1G
- // 联通在线定向流量集约平台-沃悦读
- // system_id: ,
- // "SOURCEDEVICE_ID":"650000"
- const params = {
- "SPID": $("#productSelect").find("option:selected").attr('spid'),
- "PRODUCT_ID": $("#productSelect").find("option:selected").attr('prmproductid'),
- "PRODUCT_NAME": $("#productSelect").find("option:selected").attr('productname'),
- "PRODUCT_PRICE": $("#productSelect").find("option:selected").attr('productprice'),
- "PRODUCT_TYPE": $("#productSelect").find("option:selected").attr('producttype')
- };
- $('#product').text(JSON.stringify(params))
- })
- $('#btn-order').unbind('click').on('click', function() {
- $("#btn-order").attr('disabled', true);
- $("body").css("overflow", "hidden");
- let capUrl = $('#evnSelect').find("option:selected").attr('capurl');
- // var $iframe = $('<iframe id="uniauthframe" src="https://cap.chinaunicom.cn/CAP-AUTH/"></iframe>')
- var $iframe = $('<iframe id="uniauthframe" src="'+capUrl+'"></iframe>')
- // var $iframe = $('<iframe id="uniauthframe" src="http://cap.free.svipss.top/cap_auc_frontpage/webapp/auth-dx.html"></iframe>')
- var targetOrigin = "";
- if (capUrl.indexOf("https://cap.chinaunicom.cn") >= 0) {
- targetOrigin = "https://cap.chinaunicom.cn/";
- } else if (capUrl.indexOf("http://cap.free.svipss.top") >= 0) {
- targetOrigin = "http://cap.free.svipss.top/"
- } else if (capUrl.indexOf("https://captain.chinaunicom.cn")) {
- targetOrigin = "https://captain.chinaunicom.cn/"
- }
- var PRODUCT_NAME = $("#productSelect").find("option:selected").attr('productname');
- var PRODUCT_PRICE = $("#productSelect").find("option:selected").attr('productprice');
- var PRODUCT_ID = $("#productSelect").find("option:selected").attr('prmproductid');
- var PRODUCT_TYPE = $("#productSelect").find("option:selected").attr('producttype');
- var SPID = $("#productSelect").find("option:selected").attr('spid');
- var params = {
- "PRODUCT_NAME": PRODUCT_NAME,
- "PRODUCT_PRICE": PRODUCT_PRICE,
- "CLIENT_ID": "",
- "CLIENT": "3",
- "SERVICE_ID": "",
- "AUTH_NO": "",
- "CLIENT_SECRET": "",
- "VERSION": "1.0",
- "SERVICE_PHONE": "",
- "THEME": "",
- "PRODUCT_ID": PRODUCT_ID,
- "PRODUCT_TYPE": PRODUCT_TYPE
- }
- $iframe.on('load', function() {
- $.ajax({
- //请求后项定向服务获取
- url: getRootPath() + "-s1api" + "/ini/clientsecret?spid=" + SPID,
- dataType: "JSON",
- method: "GET",
- success: function(data) {
- params.CLIENT_ID = data.client_id;
- params.AUTH_NO = data.auth_no;
- params.CLIENT_SECRET = data.client_secret;
- console.log(params)
- $('#uniauthframe')[0].contentWindow.postMessage(
- JSON.stringify(params), targetOrigin)
- }
- })
- })
- $('body').append($iframe);
- //监听统一认证结果
- window.addEventListener('message', function(e) {
- let data = JSON.parse(e.data);
- $('#token').text(e.data)
- switch (data.RSP.RSP_CODE) {
- case "0000": //处理成功
- $('iframe').remove();
- break;
- case "0001": //auth_no无效 (入参流水)
- alert("认证失败!");
- break;
- case "0003": //client_id不存在 (注册id存在问题)
- alert("认证失败!");
- break;
- case "4444": //服务暂时不可用(系统忙/系统队列满)
- alert("服务暂时不可用!");
- break;
- case "9001": //关闭H5认证页面
- $('iframe').remove();
- break;
- }
- }, false);
- })
- /*
- 获取root
- */
- function getRootPath() {
- //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
- var curWwwPath = window.document.location.href;
- //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
- var pathName = window.document.location.pathname;
- var pos = curWwwPath.indexOf(pathName);
- //获取主机地址,如: http://localhost:8080
- var localhostPath = curWwwPath.substring(0, pos);
- //获取带"/"的项目名,如:/ems
- var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
- root = (localhostPath + projectName);
- return (localhostPath + projectName);
- }
|