signature.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>demo</title>
  6. <style type="text/css">
  7. </style>
  8. </head>
  9. <body>
  10. <div class="list">
  11. </div>
  12. <script src="https://cdn.bootcss.com/jquery/1.6.2/jquery.min.js"></script>
  13. <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
  14. <script type="text/javascript">
  15. $(function ()
  16. {
  17. var sign_url = window.location.href;
  18. sign_url = encodeURIComponent(sign_url);
  19. var host = window.location.protocol + '//' + window.location.host;
  20. $.ajax({
  21. type: "get",
  22. async: false,
  23. url: host +"/mobile/index.php?act=mshop&op=signurl&client_type=ajax&sign_url=" + sign_url,
  24. dataType: "jsonp",
  25. jsonp: "callback",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback)
  26. success: function (json) {
  27. console.log(json);
  28. var jsonx = json.datas;
  29. var timestamp = jsonx.timestamp,
  30. nonceStr = jsonx.noncestr,
  31. signature = jsonx.signature,
  32. appid = jsonx.appid;
  33. wx.config({
  34. debug: false,
  35. appId: appid,
  36. timestamp: timestamp,
  37. nonceStr: nonceStr,
  38. signature: signature,
  39. jsApiList: [
  40. 'checkJsApi',
  41. 'onMenuShareTimeline',
  42. 'onMenuShareAppMessage',
  43. 'onMenuShareQQ',
  44. 'onMenuShareWeibo',
  45. 'onMenuShareQZone',
  46. 'getNetworkType',
  47. 'hideOptionMenu',
  48. 'showOptionMenu',
  49. 'chooseWXPay'
  50. ]
  51. });
  52. ready();
  53. },
  54. error: function () {
  55. alert('fail');
  56. }
  57. });
  58. function ready()
  59. {
  60. wx.ready(function ()
  61. {
  62. //分享朋友圈 / 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口
  63. wx.onMenuShareTimeline({
  64. title: "分享测试", // 分享标
  65. desc: "分享测试分享测试",
  66. link: "http://p.lrlz.com/mobile/index.php?act=mshop&op=test&client_type=wap", //cookie读取
  67. imgUrl: "http://p.lrlz.com/data/upload/shop/store/goods/6/6_05511819175096982_360.jpg",// 分享图标
  68. trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
  69. },
  70. success: function (res) {
  71. },
  72. cancel: function (res) {
  73. //alert('已取消'+res);
  74. },
  75. fail: function (res) {
  76. //alert(JSON.stringify(res));
  77. }
  78. });
  79. //分享给好友
  80. wx.onMenuShareAppMessage({
  81. title: "分享测试", // 分享标
  82. desc: "分享测试分享测试",
  83. link: "http://p.lrlz.com/mobile/index.php?act=mshop&op=test&client_type=wap", //cookie读取
  84. imgUrl: "http://p.lrlz.com/data/upload/shop/store/goods/6/6_05511819175096982_360.jpg",// 分享图标
  85. trigger: function (res) {
  86. // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
  87. },
  88. success: function (res) {
  89. }
  90. });
  91. wx.error(function (res) {
  92. alert(res.errMsg);
  93. });
  94. })
  95. }
  96. })
  97. </script>
  98. </body>
  99. </html>