必须通过HTML链接使用base64进行编码

时间:2019-10-15 14:24:56

标签: javascript html forms

这是我的第一篇文章,希望以前不会解决。 我正在使用呼叫中心软件,也正在使用Salesforce Lightning。

呼叫者打来电话时,我想检查一下我的CRM是否是客户。 使用Salesforce的基本版本很容易实现,但由于链接是使用base64编码的,因此不再可用。 请阅读这篇文章以获取更多说明:https://tomsmalara.blogspot.com/2019/01/create-lightning-component-that.html

因此,我必须创建一个用于收集呼叫者电话号码的HTML页面,并撰写+加密Salesforce链接并打开已加密的链接。

<!DOCTYPE html>
<html>
	<head>
		<title>Waiting a call ...</title>
			<style> 
				body {text-align: center;} 
			</style> 
	</head>
	<body>
		<form name="form1" onsubmit="event.preventDefault();return displayResult();">
			<label for="name">Phone number:</label>
			<input type="text" id="PhoneNumber" name="PhoneNumber" size="10">
			<div id="myEncoding"></div>
		</form>	
		<script>
			function b64EncodeUnicode(PhoneNumber) {
				// first we use encodeURIComponent to get percent-encoded UTF-8,
				// then we convert the percent encodings into raw bytes which
				// can be fed into btoa.
				
				var Mytxt = '{"componentDef":"forceSearch:search","attributes":{"term":"'+PhoneNumber+'","scopeMap":{"resultsCmp":"forceSearch:resultsTopResults","label":"Top Results","type":"TOP_RESULTS","cacheable":"Y","id":"TOP_RESULTS","labelPlural":"Top Results"},"context":{"disableSpellCorrection":false,"SEARCH_ACTIVITY":{"term":1234567890}}},"state":{}}';
				
				return btoa(encodeURIComponent(Mytxt).replace(/%([0-9A-F]{2})/g,
					function toSolidBytes(match, p1) {
						var MyResult = String.fromCharCode('0x' + p1);
						return MyResult;
				}));
			}

			function displayResult() {
				var result = b64EncodeUnicode(PhoneNumber);
				document.getElementById('myEncoding').innerHTML = result;
				return false;
				window.open("https://mycompany.lightning.force.com/one/one.app#" +result,,,true)
			}
		</script>
	</body>
</html>

出了点问题,尝试了不同的尝试而没有结果。 如果有人能找到问题并向我解释,我将非常感谢 预先谢谢你

2 个答案:

答案 0 :(得分:0)

好的,谢谢您的回答。 所以,我更改了代码,看起来效果更好

<!DOCTYPE html>
<html>
	<head>
		<title>Waiting a call ...</title>
			<style> 
				body {text-align: center;} 
			</style> 
	</head>
	<body>
		<form>
			<label for="phone">Phone number:</label>
			<input type="text" id="PhoneNumber" name="PhoneNumber1" oninput=encode()>
			<div id="myEncoding"></div>
		</form>

        <script> 
        function encode() { 
			var original = document.getElementById('PhoneNumber').value; 
            var stringToEncode = '{"componentDef":"forceSearch:search","attributes":{"term":"'+original+'","scopeMap":{"resultsCmp":"forceSearch:resultsTopResults","label":"Top Results","type":"TOP_RESULTS","cacheable":"Y","id":"TOP_RESULTS","labelPlural":"Top Results"},"context":{"disableSpellCorrection":false,"SEARCH_ACTIVITY":{"term":1234567890}}},"state":{}}';
            var encoded = window.btoa(stringToEncode); 
  
            var output = "Encoded String : " + encoded; 
            document.getElementById("myEncoding").innerHTML = 
              "Original String: " + original + "<br>" + output; 
			window.location.assign("https://mycompany.lightning.force.com/lightning/one/one.app?source=alohaHeader#")+searchcriteria;
        } 
    </script> 
	</body>
</html>

现在,我还有一个问题,是否可以不用输入框来接收电话号码。我想在接收到参数(电话号码)的情况下自动在我的网页中执行JScr​​ipt吗? 此刻,我分两步完成了,但也许我可以一步完成?

答案 1 :(得分:0)

请找到我发现可以删除输入步骤的解决方案...

<!DOCTYPE html>
<html>
	<head>
		<title>Waiting a call ...</title>
			<style> 
				body {text-align: center;} 
			</style> 
	</head>
	<body onload=acceptParam()>
		Waiting a call ...

		<script> 
			function acceptParam(){
			  var hashParams = window.location.href.substr(1).split('?'); // substr(1) to remove the `#`
			  hashParams = hashParams[1].split('&');
			  var p = hashParams[0].split('=');
			  //document.getElementById('PhoneNumber').value = p[1] // Pour info
			  
			  var stringToEncode = '{"componentDef":"forceSearch:searchPage","attributes":{"term":"'+p[1]+'","scopeMap":{"type":"TOP_RESULTS"},"context":{"disableSpellCorrection":false,"disableIntentQuery":false,"permsAndPrefs":{"SearchUi.searchUIPilotFeatureEnabled":false,"SearchExperience.LeftNavEnhancementEnabled":true,"Search.crossObjectsAutoSuggestEnabled":true,"SearchResultsLVM.lvmEnabledForSearchResultsOn":true,"MySearch.userCanHaveMySearchBestResult":false,"SearchResultsLVM.lvmEnabledForTopResults":false,"OrgPermissions.UnionAppNavSmartScope":false,"SearchUi.feedbackComponentEnabled":false,"SearchExperience.TopResultsSingleSOSLEnabled":false,"OrgPreferences.ChatterEnabled":true,"Search.maskSearchInfoInLogs":false,"SearchUi.orgHasAccessToSearchTermHistory":false,"SearchUi.searchUIInteractionLoggingEnabled":false,"MySearch.userCanHaveMySearch":false},"searchDialogSessionId":"bdded2dc-91d1-3b3e-11d7-ff339bce1727","searchSource":"INPUT_DESKTOP"},"groupId":"DEFAULT"},"state":{}}'
			  var encoded = window.btoa(stringToEncode); 
	  
			  //var output = "Encoded String : " + encoded; 
			  //document.getElementById("myEncoding").innerHTML = "Original String: " + p[1] + "<br>" + output; 
			  window.location.assign("https://mycompany.lightning.force.com/lightning/one/one.app?source=alohaHeader#"+encoded);
			} 
	   </script> 
	</body>
</html>

请问,您能对我说一下吗?也许我们可以提高效率?