Javascript 向Office和SharePoint加载项添加许可证检查
已创建Office加载项(应用程序ID 42949681619) 执行 发送以供批准。收到一条评论“您的外接程序未按外接程序说明中的说明工作。单击“选择”按钮时不会发生任何情况。” 测试许可证验证服务工作正常(IsTest=True,IsValid=False)。 我哪里出错了? 如何检查此(正确)许可证Javascript 向Office和SharePoint加载项添加许可证检查,javascript,Javascript,已创建Office加载项(应用程序ID 42949681619) 执行 发送以供批准。收到一条评论“您的外接程序未按外接程序说明中的说明工作。单击“选择”按钮时不会发生任何情况。” 测试许可证验证服务工作正常(IsTest=True,IsValid=False)。 我哪里出错了? 如何检查此(正确)许可证 var decodedToken = getUrlVars()["et"]; var decodedBytes = encodeURIComponent(decodedToken); var
var decodedToken = getUrlVars()["et"];
var decodedBytes = encodeURIComponent(decodedToken);
var Valid = false;
function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
function EtokenWeb(sourceWord) {
try {
var xhr = new XMLHttpRequest();
var translateRequest = "../Verification.asmx/VerifyEntitlement?et="+ sourceWord;
xhr.open("POST", translateRequest);
xhr.responseType = 'document';
xhr.onload = function () {
var result = parseResponse(xhr.responseXML);
Valid = result;
}
// Send the HTTP request.
xhr.send();
}
catch (ex) {
app.showNotification(ex.name, ex.message);
}
}
function parseResponse(responseText) {
var response = "Cannot read response.",
xmlDoc;
try {
response = responseText.getElementsByTagName("string")[0].firstChild.nodeValue;
}
catch (ex) {
app.showNotification(ex.name, ex.message);
}
return response;
}
using BenWeb.VerificationService;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace BenWeb
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Verification : System.Web.Services.WebService
{
private static VerificationServiceClient service = new VerificationServiceClient();
VerifyEntitlementTokenRequest request = new VerifyEntitlementTokenRequest();
[WebMethod]
public bool VerifyEntitlement ()
{
// Store the URL from the incoming request and declare
// strings to store the query and the translation result.
string currentURL = HttpContext.Current.Request.RawUrl;
string queryString;
bool result = false;
try
{
// Check to make sure some query string variables exist.
int indexQueryString = currentURL.IndexOf('?');
if (indexQueryString >= 0)
{
queryString = (indexQueryString < currentURL.Length - 1) ? currentURL.Substring(indexQueryString + 1) : String.Empty;
// Parse the query string variables into a NameValueCollection.
NameValueCollection queryStringCollection = HttpUtility.ParseQueryString(queryString);
string Token = queryStringCollection["et"];
if (Token != null)
{
request.EntitlementToken = Token;
VerifyEntitlementTokenResponse omexResponse = service.VerifyEntitlementToken(request);
result = omexResponse.IsValid;
}
else result = false;
}
}
catch (Exception ex)
{
//result = ex.Message;
result = false;
}
// to the HTTP request.
return result;
}
}
}
if (Valid)
{
$('#highlight-button').click(SelectedRange);
$('#highlight2-button').click(Recalculation);
}