Bez popisu

inviteApp.js 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var user_id,token,source = '0';
  2. var qs = parseQueryString(location.href);
  3. $().ready(function(){
  4. getTokenAddUserIdEvent();//获取token 等信息
  5. })
  6. $(".button").on("click",function(){
  7. var param = {
  8. "shareImageUrl": "https://credit-loan.oss-cn-beijing.aliyuncs.com/Uploads/logo/60%403x.png",
  9. "shareTitle": "信贷经理线上获客神器",
  10. "shareDescirpt": "真实一手好单,时时推送,边抢边赚钱,邀好友免费抢单~",
  11. "shareUrl": getLocation()+"/inviteWeixin.html?user_id=" + user_id + '&source=' + source,//详情链接
  12. "shareType": 1 //1:微信好友 2:朋友圈
  13. }
  14. param = JSON.stringify(param);
  15. try {
  16. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  17. window.webkit.messageHandlers.shareWithWechatSession.postMessage(param);
  18. }
  19. if (navigator.userAgent.match(/android/i)) {
  20. obj4H5.shareWithWechatSession(param);
  21. }
  22. } catch (error) {
  23. }
  24. })
  25. // 获取token
  26. function getTokenAddUserIdEvent () {
  27. //获取token 和 user_id
  28. var param = '{"js_callback" : "getTokenAddUserId"}';
  29. try{
  30. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  31. window.webkit.messageHandlers.app_h5_getTokenAndUserid.postMessage(param);
  32. }
  33. if(navigator.userAgent.match(/android/i)){
  34. obj4H5.app_h5_getTokenAndUserid(param);
  35. }
  36. }catch(e){
  37. console.log("兼容");
  38. // token = '2b288bf6765af2147392e85d40380014'
  39. // user_id = '6'
  40. // inviteInformation();//获得的金币数量
  41. }
  42. }
  43. function getTokenAddUserId (data) {//app token 回调
  44. var dataes = JSON.parse(data)
  45. token = dataes.token;
  46. user_id = dataes.user_id;
  47. if(dataes.source){source = dataes.source}
  48. inviteInformation();//获得的金币数量
  49. }
  50. function inviteInformation () {
  51. //获取邀请好友数量以及获得的金币数量
  52. $.ajax({
  53. url:'/user/inviteInformation',
  54. type:'get',
  55. dataType:'json',
  56. headers:{
  57. token:token
  58. },
  59. success: function (res){
  60. if(res && res.errno == 0){
  61. $("#inviteNum").html(res.rst.invite_num);
  62. $("#inviteGold").html(res.rst.invite_gold);
  63. $(".myReward span").html(res.rst.invite_gold + '江湖币');
  64. $("#authNum").html(res.rst.auth_num);
  65. }
  66. },
  67. error: function (err){
  68. }
  69. })
  70. }
  71. // 获取上级地址
  72. function getLocation() {
  73. var upper=window.location.href.split("/")[window.location.href.split("/").length-1]
  74. return window.location.href.replace(upper,"");
  75. }
  76. //获取地址栏参数
  77. function parseQueryString(url) {
  78. var urlObj = {};
  79. var reg = /([^?=&]+)=([^?=&]+)/g;
  80. url.replace(reg, function($0, $1, $2) {
  81. urlObj[$1] = decodeURIComponent($2);
  82. })
  83. return urlObj;
  84. }