ASP调用SDK微信分享好友、朋友圈

时间:2021-05-23 23:55:16   收藏:0   阅读:0

 ASP调用SDK微信分享好友、朋友圈需要用到sha1.asp,我先来上主代码,然后再附加sha1.asp,方便大家直接复制过去即可使用。

页面:shara.asp

 1 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
 2 <!--#include file="sha1.asp"-->
 3 <%
 4  On Error Resume Next
 5  Dim WxObj
 6  Set WxObj = Server.CreateObject("WeixinDLL.WeixinClass")
 7  WxObj.SetAppID      = "AppID"
 8  WxObj.SetAppSecret  = "AppSecret"
 9  
10  Dim token,JsapiTicket,timestamp,nonceStr,signature,sha1Url
11  token = WxObj.Get_Token()  当前用户的access_token
12  If Trim(token) = "" Or IsNull(token) Then Response.Write "没有获取到有效的access_token,导致模板消息发送失败!" : Response.End()
13  sha1Url = "https://www.domain.com/shara/shara.asp"
14  timestamp = WxObj.ToUnixTime(now)
15  nonceStr  = WxObj.MakeRanNumChar(12)
16  JsapiTicket = WxObj.Get_Ticket(token)
17  signature = Get_signature(JsapiTicket,nonceStr,timestamp,sha1Url)
18  signature=sha1("jsapi_ticket=" & JsapiTicket & "&noncestr=" & nonceStr & "&timestamp=" & timestamp & "&url=" & sha1Url & "")
19  Set WxObj = Nothing
20  If Err Then Response.Write Err.Description
21 %>
22 <!DOCTYPE html>
23 <html>
24 <head>
25   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
26   <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
27   <title>分享好友、朋友圈</title>
28   <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
29 </head>
30 <body>
31 <div style="display:block; width:95%; height:300px; border:1px solid #ddd; background:#f2f2f2; margin:20px auto;">
32   <div id="showid">分享给好友、朋友圈,点击分享面板进行测 试</div>
33 </div>
34 <script type="text/javascript">
35 window.onload = function(){
36    wx.config({
37         debug: false,// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
38         appId: "<%=AppID%>",
39         timestamp: "<%=timestamp%>",
40         nonceStr: "<%=nonceStr%>",
41         signature: "<%=signature%>",
42         jsApiList: [onMenuShareTimeline,onMenuShareAppMessage,updateTimelineShareData,updateAppMessageShareData/* 所有要调用的 API 都要加到这个列表中*/
43    });
44    //----------------------------------------------------
45    wx.ready(function(){
46       var Url = "https://www.domain.com/shara/shara.asp";
47       var Title = "元森美";
48       var Description = "元森美水果酵素粉:湖南元生康生物科技有限公司的纯绿色健康产品!";
49       var ImgUrl = "https://www.domain.com/img/smal.jpg";
50       // 分享到朋友圈
51       wx.onMenuShareTimeline({ 
52          title: Title, // 分享标题
53          link: Url, // 分享链接
54          imgUrl: ImgUrl, // 分享图标
55          success: function () {
56            // 用户确认分享后执行的回调函数
57          },
58          cancel: function () {
59            // 用户取消分享后执行的回调函数
60          }
61       });
62       //分享给微信好友
63       wx.onMenuShareAppMessage({
64          title: Title, // 分享标题
65          desc: Description, // 分享描述
66          link: Url, // 分享链接
67          imgUrl: ImgUrl, // 分享图标
68          success: function () {
69             // 用户确认分享后执行的回调函数
70          },
71          cancel: function () {
72            // 用户取消分享后执行的回调函数
73          }
74       });
75       wx.updateTimelineShareData({
76          title: Title,
77          link: Url,
78          imgUrl: ImgUrl,
79          success: function(){}
80       });
81       // 自定义“分享给朋友”及“分享到QQ”按钮的分享内容
82       wx.updateAppMessageShareData({
83          title: Title,
84          desc: Description,
85          link: Url,
86          imgUrl: ImgUrl,
87          success: function(){}
88       });
89       
90    });
91    //----------------------------------------------------
92 }
93 </script>
94 </body>
95 </html>

本处代码用到了WeixinDLL,如需要可以联系我VX:z18670092211

sha1.asp 页代码

  1 <script language="JScript" runAt="server">
  2 // MD5 SHA1 共用
  3 function add(x, y)
  4 {
  5   return ((x&0x7FFFFFFF) + (y&0x7FFFFFFF)) ^ (x&0x80000000) ^ (y&0x80000000);
  6 }
  7 
  8 // MD5
  9 function MD5hex(i)
 10 {
 11   var sHex = "0123456789abcdef"
 12   h = "";
 13   for(j = 0; j <= 3; j++)
 14   {
 15     h += sHex.charAt((i >> (j * 8 + 4)) & 0x0F) +
 16          sHex.charAt((i >> (j * 8)) & 0x0F);
 17   }
 18   return h;
 19 }
 20 
 21 function R1(A, B, C, D, X, S, T)
 22 {
 23   q = add(add(A, (B & C) | (~B & D)), add(X, T));
 24   return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
 25 }
 26 
 27 function R2(A, B, C, D, X, S, T)
 28 {
 29   q = add(add(A, (B & D) | (C & ~D)), add(X, T));
 30   return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
 31 }
 32 
 33 function R3(A, B, C, D, X, S, T)
 34 {
 35   q = add(add(A, B ^ C ^ D), add(X, T));
 36   return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
 37 }
 38 
 39 function R4(A, B, C, D, X, S, T)
 40 {
 41   q = add(add(A, C ^ (B | ~D)), add(X, T));
 42   return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
 43 }
 44 
 45 function MD5(sInp) {
 46   var sAscii = " !\"#$%&‘()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
 47   wLen = (((sInp.length + 8) >> 6) + 1) << 4;
 48   var X = new Array(wLen);
 49 
 50   j = 4;
 51   for (i = 0; (i * 4) < sInp.length; i++)
 52   {
 53     X[i] = 0;
 54     for (j = 0; (j < 4) && ((j + i * 4) < sInp.length); j++)
 55     {
 56       X[i] += (sAscii.indexOf(sInp.charAt((i * 4) + j)) + 32) << (j * 8);
 57     }
 58   }
 59 
 60   if (j == 4)
 61   {
 62     X[i++] = 0x80;
 63   }
 64   else
 65   {
 66     X[i - 1] += 0x80 << (j * 8);
 67   }
 68   for(; i < wLen; i++) { X[i] = 0; }
 69   X[wLen - 2] = sInp.length * 8;
 70 
 71   a = 0x67452301;
 72   b = 0xefcdab89;
 73   c = 0x98badcfe;
 74   d = 0x10325476;
 75 
 76   for (i = 0; i < wLen; i += 16) {
 77     aO = a;
 78     bO = b;
 79     cO = c;
 80     dO = d;
 81 
 82     a = R1(a, b, c, d, X[i+ 0], 7 , 0xd76aa478);
 83     d = R1(d, a, b, c, X[i+ 1], 12, 0xe8c7b756);
 84     c = R1(c, d, a, b, X[i+ 2], 17, 0x242070db);
 85     b = R1(b, c, d, a, X[i+ 3], 22, 0xc1bdceee);
 86     a = R1(a, b, c, d, X[i+ 4], 7 , 0xf57c0faf);
 87     d = R1(d, a, b, c, X[i+ 5], 12, 0x4787c62a);
 88     c = R1(c, d, a, b, X[i+ 6], 17, 0xa8304613);
 89     b = R1(b, c, d, a, X[i+ 7], 22, 0xfd469501);
 90     a = R1(a, b, c, d, X[i+ 8], 7 , 0x698098d8);
 91     d = R1(d, a, b, c, X[i+ 9], 12, 0x8b44f7af);
 92     c = R1(c, d, a, b, X[i+10], 17, 0xffff5bb1);
 93     b = R1(b, c, d, a, X[i+11], 22, 0x895cd7be);
 94     a = R1(a, b, c, d, X[i+12], 7 , 0x6b901122);
 95     d = R1(d, a, b, c, X[i+13], 12, 0xfd987193);
 96     c = R1(c, d, a, b, X[i+14], 17, 0xa679438e);
 97     b = R1(b, c, d, a, X[i+15], 22, 0x49b40821);
 98 
 99     a = R2(a, b, c, d, X[i+ 1], 5 , 0xf61e2562);
100     d = R2(d, a, b, c, X[i+ 6], 9 , 0xc040b340);
101     c = R2(c, d, a, b, X[i+11], 14, 0x265e5a51);
102     b = R2(b, c, d, a, X[i+ 0], 20, 0xe9b6c7aa);
103     a = R2(a, b, c, d, X[i+ 5], 5 , 0xd62f105d);
104     d = R2(d, a, b, c, X[i+10], 9 ,  0x2441453);
105     c = R2(c, d, a, b, X[i+15], 14, 0xd8a1e681);
106     b = R2(b, c, d, a, X[i+ 4], 20, 0xe7d3fbc8);
107     a = R2(a, b, c, d, X[i+ 9], 5 , 0x21e1cde6);
108     d = R2(d, a, b, c, X[i+14], 9 , 0xc33707d6);
109     c = R2(c, d, a, b, X[i+ 3], 14, 0xf4d50d87);
110     b = R2(b, c, d, a, X[i+ 8], 20, 0x455a14ed);
111     a = R2(a, b, c, d, X[i+13], 5 , 0xa9e3e905);
112     d = R2(d, a, b, c, X[i+ 2], 9 , 0xfcefa3f8);
113     c = R2(c, d, a, b, X[i+ 7], 14, 0x676f02d9);
114     b = R2(b, c, d, a, X[i+12], 20, 0x8d2a4c8a);
115 
116     a = R3(a, b, c, d, X[i+ 5], 4 , 0xfffa3942);
117     d = R3(d, a, b, c, X[i+ 8], 11, 0x8771f681);
118     c = R3(c, d, a, b, X[i+11], 16, 0x6d9d6122);
119     b = R3(b, c, d, a, X[i+14], 23, 0xfde5380c);
120     a = R3(a, b, c, d, X[i+ 1], 4 , 0xa4beea44);
121     d = R3(d, a, b, c, X[i+ 4], 11, 0x4bdecfa9);
122     c = R3(c, d, a, b, X[i+ 7], 16, 0xf6bb4b60);
123     b = R3(b, c, d, a, X[i+10], 23, 0xbebfbc70);
124     a = R3(a, b, c, d, X[i+13], 4 , 0x289b7ec6);
125     d = R3(d, a, b, c, X[i+ 0], 11, 0xeaa127fa);
126     c = R3(c, d, a, b, X[i+ 3], 16, 0xd4ef3085);
127     b = R3(b, c, d, a, X[i+ 6], 23,  0x4881d05);
128     a = R3(a, b, c, d, X[i+ 9], 4 , 0xd9d4d039);
129     d = R3(d, a, b, c, X[i+12], 11, 0xe6db99e5);
130     c = R3(c, d, a, b, X[i+15], 16, 0x1fa27cf8);
131     b = R3(b, c, d, a, X[i+ 2], 23, 0xc4ac5665);
132 
133     a = R4(a, b, c, d, X[i+ 0], 6 , 0xf4292244);
134     d = R4(d, a, b, c, X[i+ 7], 10, 0x432aff97);
135     c = R4(c, d, a, b, X[i+14], 15, 0xab9423a7);
136     b = R4(b, c, d, a, X[i+ 5], 21, 0xfc93a039);
137     a = R4(a, b, c, d, X[i+12], 6 , 0x655b59c3);
138     d = R4(d, a, b, c, X[i+ 3], 10, 0x8f0ccc92);
139     c = R4(c, d, a, b, X[i+10], 15, 0xffeff47d);
140     b = R4(b, c, d, a, X[i+ 1], 21, 0x85845dd1);
141     a = R4(a, b, c, d, X[i+ 8], 6 , 0x6fa87e4f);
142     d = R4(d, a, b, c, X[i+15], 10, 0xfe2ce6e0);
143     c = R4(c, d, a, b, X[i+ 6], 15, 0xa3014314);
144     b = R4(b, c, d, a, X[i+13], 21, 0x4e0811a1);
145     a = R4(a, b, c, d, X[i+ 4], 6 , 0xf7537e82);
146     d = R4(d, a, b, c, X[i+11], 10, 0xbd3af235);
147     c = R4(c, d, a, b, X[i+ 2], 15, 0x2ad7d2bb);
148     b = R4(b, c, d, a, X[i+ 9], 21, 0xeb86d391);
149 
150     a = add(a, aO);
151     b = add(b, bO);
152     c = add(c, cO);
153     d = add(d, dO);
154   }
155   
156    MD5Value=MD5hex(a) + MD5hex(b) + MD5hex(c) + MD5hex(d);
157    return MD5Value.toUpperCase();
158 }
159 
160 
161 // SHA1
162 
163 function SHA1hex(num)
164 {
165   var sHEXChars="0123456789abcdef";
166   var str="";
167   for(var j=7;j>=0;j--)
168     str+=sHEXChars.charAt((num>>(j*4))&0x0F);
169   return str;
170 }
171 
172 function AlignSHA1(sIn){
173   var nblk=((sIn.length+8)>>6)+1, blks=new Array(nblk*16);
174   for(var i=0;i<nblk*16;i++)blks[i]=0;
175   for(i=0;i<sIn.length;i++)
176     blks[i>>2]|=sIn.charCodeAt(i)<<(24-(i&3)*8);
177   blks[i>>2]|=0x80<<(24-(i&3)*8);
178   blks[nblk*16-1]=sIn.length*8;
179   return blks;
180 }
181 
182 
183 function rol(num,cnt){
184   return(num<<cnt)|(num>>>(32-cnt));
185 }
186 
187 function ft(t,b,c,d){
188   if(t<20)return(b&c)|((~b)&d);
189   if(t<40)return b^c^d;
190   if(t<60)return(b&c)|(b&d)|(c&d);
191   return b^c^d;
192 }
193 
194 function kt(t) {
195   return(t<20)?1518500249:(t<40)?1859775393:
196     (t<60)?-1894007588:-899497514;
197 }
198 
199 function SHA1(sIn)
200 {
201   var x=AlignSHA1(sIn);
202   var w=new Array(80);
203   var a=1732584193;
204   var b=-271733879;
205   var c=-1732584194;
206   var d=271733878;
207   var e=-1009589776;
208   for(var i=0;i<x.length;i+=16){
209     var olda=a;
210     var oldb=b;
211     var oldc=c;
212     var oldd=d;
213     var olde=e;
214     for(var j=0;j<80;j++){
215       if(j<16)w[j]=x[i+j];
216       else w[j]=rol(w[j-3]^w[j-8]^w[j-14]^w[j-16],1);
217       t=add(add(rol(a,5),ft(j,b,c,d)),add(add(e,w[j]),kt(j)));
218       e=d;
219       d=c;
220       c=rol(b,30);
221       b=a;
222       a=t;
223     }
224     a=add(a,olda);
225     b=add(b,oldb);
226     c=add(c,oldc);
227     d=add(d,oldd);
228     e=add(e,olde);
229   }
230     SHA1Value=SHA1hex(a)+SHA1hex(b)+SHA1hex(c)+SHA1hex(d)+SHA1hex(e);
231    return SHA1Value.toUpperCase();
232 }
233 
234 </script>

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!