wechat.mta.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var weixin_jssdk_ops = {
  2. init: function (share_opts) {
  3. this.initJSconfig(share_opts);
  4. },
  5. initJSconfig: function (share_opts) {
  6. $.ajax({
  7. url: '//wd.leiting.com/api/wechat',
  8. data: {
  9. url : share_opts.url,
  10. key : share_opts.key
  11. },
  12. type: 'get',
  13. dataType: 'jsonp',
  14. jsonp:"jsonpcallback",
  15. success: function (data) {
  16. if (data.status == 'success') {
  17. var appId = data.message.appId;
  18. var timestamp = data.message.timestamp;
  19. var nonceStr = data.message.nonceStr;
  20. var signature = data.message.signature;
  21. wx.config({
  22. debug: false,
  23. appId: appId,
  24. timestamp: timestamp,
  25. nonceStr: nonceStr,
  26. signature: signature,
  27. jsApiList: [
  28. 'onMenuShareTimeline', 'onMenuShareAppMessage'
  29. ]
  30. });
  31. weixin_jssdk_ops.ready(share_opts);
  32. wx.error(function (res) {
  33. console.log(res);
  34. });
  35. }
  36. }
  37. });
  38. },
  39. ready: function(share_opts){
  40. wx.ready(function () {
  41. if (!share_opts.link) {
  42. share_opts.link = share_opts.url;
  43. }
  44. wx.onMenuShareTimeline({
  45. title: share_opts.title,
  46. imgUrl: share_opts.img,
  47. link: share_opts.link,
  48. success: function () {
  49. if(MtaH5){
  50. MtaH5.clickStat("weixin")
  51. MtaH5.clickShare('wechat_moments');
  52. }
  53. }
  54. });
  55. wx.onMenuShareAppMessage({
  56. title: share_opts.title,
  57. desc: share_opts.desc,
  58. link: share_opts.link,
  59. imgUrl: share_opts.img,
  60. type: 'link',
  61. success: function () {
  62. if(MtaH5){
  63. MtaH5.clickStat("weixin")
  64. MtaH5.clickShare('wechat_friend');
  65. }
  66. }
  67. });
  68. });
  69. }
  70. };