//==== 微信签名功能 ==== import Req from './jun_httpInstall' // http 请求 import appId from '../config/appid' // appid // js SHA (function(D){function p(b,e,c){var a=0,d=[0],f="",g=null,f=c||"UTF8";if("UTF8"!==f&&"UTF16"!==f)throw"encoding must be UTF8 or UTF16";if("HEX"===e){if(0!==b.length%2)throw"srcString of HEX type must be in byte increments";g=v(b);a=g.binLen;d=g.value}else if("TEXT"===e)g=w(b,f),a=g.binLen,d=g.value;else if("B64"===e)g=x(b),a=g.binLen,d=g.value;else if("BYTES"===e)g=y(b),a=g.binLen,d=g.value;else throw"inputFormat must be HEX, TEXT, B64, or BYTES";this.getHash=function(b,f,c,e){var g=null,h=d.slice(),l=a,n;3===arguments.length?"number"!==typeof c&&(e=c,c=1):2===arguments.length&&(c=1);if(c!==parseInt(c,10)||1>c)throw"numRounds must a integer >= 1";switch(f){case "HEX":g=z;break;case "B64":g=A;break;case "BYTES":g=B;break;default:throw"format must be HEX, B64, or BYTES";}if("SHA-1"===b)for(n=0;nn/8&&(h[b]&=4294967040);for(l=0;l<=b;l+=1)p[l]=h[l]^909522486,t[l]=h[l]^1549556828;if("SHA-1"===e)e=s(t.concat(s(p.concat(d),c+a)),c+r);else throw"Unexpected error in HMAC implementation";return g(e,C(q))}}function w(b,e){var c=[],a,d=[],f=0,g;if("UTF8"===e)for(g=0;ga?d.push(a):2048>a?(d.push(192|a>>>6),d.push(128|a&63)):55296>a||57344<=a?d.push(224|a>>>12,128|a>>>6&63,128|a&63):(g+=1,a=65536+((a&1023)<<10|b.charCodeAt(g)&1023),d.push(240|a>>>18,128|a>>>12&63,128|a>>>6&63,128|a&63)),a=0;a>>2)+1>c.length&&c.push(0),c[f>>>2]|=d[a]<<24-f%4*8,f+=1;else if("UTF16"===e)for(g=0;g>>2)+1>c.length&&c.push(0),c[f>>>2]|=b.charCodeAt(g)<<16-f%4*8,f+=2;return{value:c,binLen:8*f}}function v(b){var e=[],c=b.length,a,d;if(0!==c%2)throw"String of HEX type must be in byte increments";for(a=0;a>>3]|=d<<24-a%8*4}return{value:e,binLen:4*c}}function y(b){var e=[],c,a;for(a=0;a>>2)+1>e.length&&e.push(0),e[a>>>2]|=c<<24-a%4*8;return{value:e,binLen:8*b.length}}function x(b){var e=[],c=0,a,d,f,g,m;if(-1===b.search(/^[a-zA-Z0-9=+\/]+$/))throw"Invalid character in base-64 string";a=b.indexOf("=");b=b.replace(/\=/g,"");if(-1!==a&&a{ // jssdk console.log(res) var ticket = res.inf.ticket sessionStorage.setItem('jsapi_ticket', ticket); sessionStorage.setItem('shareImg', res.inf.shareImg); sessionStorage.setItem('shareTitle', res.inf.shareTitle); sessionStorage.setItem('shareDesc', res.inf.shareDesc); typeof cb === 'function' && cb(); }) } var times = 0 // 微信签名 function sign(){ times += 1 var timestamp = ((new Date()).getTime()+'').substr(0,10), nonceStr = GetRndCode(8)+'', // url = encodeURIComponent(location.href.split('#')[0]), url = location.href.split('#')[0], jsapi_ticket = window.sessionStorage.getItem('jsapi_ticket'), str = "jsapi_ticket="+jsapi_ticket+"&noncestr="+nonceStr+"×tamp="+timestamp+"&url="+url, signature = new jsSHA(str,"TEXT").getHash("SHA-1","HEX"); wxConfig.timestamp = timestamp; wxConfig.nonceStr = nonceStr; wxConfig.signature = signature; console.log(str) wx.config(wxConfig); wx.error(function(res){ console.log(res) if(refreshTicket && times<2){ refreshTicket(sign); }else{ // alert(res.errMsg); } }); } // 主函数 function main(callback){ var isWx = /micromessenger/.test(navigator.userAgent.toLowerCase()); // https去掉 // && /^https/.test(location.href) if(isWx){ getJsTicket(function(){ sign() }) } } export default { main }