as.js 24.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
// var HDP = require("./hdp-4.4.0.min.js")

var as = {};

/*------------------初始化基础数据 start---------------------*/
as.domains = "https://" + document.domain + "/4Gh6/";
as.AppID = "0489fba68acd11e98c527cd30aeb749e";
as.AppKey = "9524a3c59a5d4460bd141a2a93a5db17";

//默认头像
as.defineAvatar = "http://cdn.aiwanpai.com/s/d.jpg";

as.shareLink = as.domains + "index.html";
as.shareTitle = "";
as.shareDesc = "";
as.shareImgUrl = as.domains + "share.jpg";
as.success = function () {};
as.appSuccess = function () {};

as.openid = "";
as.wxUserInfo = {};
as.isSubscribe = false; //是否关注
as.rankName = "rank"; //排行榜名称
/*------------------初始化基础数据 end-----------------------*/

/*------------------HDP初始化 start---------------------*/
HDP.init(as.AppID, as.AppKey);
weixinGetConfig();

//隐藏分享到朋友圈
hideMenuItemsTimeLink();
//隐藏微信右上角菜单
// hideOptionMenu();

//以下初始化不需要使用可以注释掉
as.weixin = HDP.weixin(); //微信
as.redis = HDP.redis(); //keyvaluestore
as.func = HDP.getFunction(); //自定义函数
as.rand = HDP.rand(); //抽奖
// as.piplus   = HDP.getPiplus();          //派加接口
as.co = HDP.getAppCooperation(); //协作
// as.rank     = HDP.rank();               //排行榜
// as.jpgCdn   = HDP.getJpgCDN();          //图片路径转换
as.wxMultimedia = HDP.wxMultimedia(); //语音
as.file = HDP.getFile(); //上传图片
/*------------------HDP初始化 end-----------------------*/

/*------------------微信相关 start---------------------*/
//分享设置
as.setShare = function (link, title, desc, imgurl) {
  as.weixin.initShare({
    "link": (link != "") ? link : as.shareLink,
    "appMessageTitle": (title != "") ? title : as.shareTitle,
    "appMessageDesc": (desc != "") ? desc : as.shareDesc,
    "appMessageImgUrl": (imgurl != "") ? imgurl : as.shareImgUrl,
    "appMessageShareSucc": as.appSuccess,

    "timelineTitle": (desc != "") ? desc : as.shareDesc,
    "timelineImgUrl": (imgurl != "") ? imgurl : as.shareImgUrl,
    "timelineShareSucc": as.success
  });
};
as.setShare("", "", "", "");

//获取用户微信信息
as.getWxUserInfo = function (callback) {
  as.weixin.getUserInfoV2({
    "success": function (res) {
      if (res && res.nickname) {
        if (res.nickname.indexOf('"') > -1) {
          res.nickname = res.nickname.replace(/"/g, '“');
        }
        if (res.nickname.indexOf("'") > -1) {
          res.nickname = res.nickname.replace(/'/g, "‘");
        }
      }
      if (res && res.avatar == "") {
        res.avatar = as.defineAvatar;
      }
      as.wxUserInfo = res;
      if (as.wxUserInfo && as.wxUserInfo.openid) {
        as.openid = as.wxUserInfo.openid;
      }

      if (typeof callback == "function") {
        callback(as.openid)
      };
    },
    "error": function (res) {
      if (typeof callback == "function") {
        callback("")
      };
    }
  });
};
//判断是否关注了公众号
as.isAttention = function (callback) {
  as.weixin.isSubscribe({
    "success": function (res) {
      as.isSubscribe = (res["subscribe"] == 1) ? true : false;
      if (typeof callback == "function")
        callback(as.isSubscribe);
    },
    "error": function (res) {
      if (typeof callback == "function")
        callback(false);
    }
  });
};
//领取卡券
as.addCard = function (cardId, openid, callback) {
  as.weixin.addCard({
    "cardId": cardId,
    "code": "",
    "openid": openid,
    "succ": function (res) {
      console.log('领取卡券成功');
      if (typeof callback == "function")
        callback(true);
    },
    "error": function (res) {
      console.log('领取卡券失败');
      if (typeof callback == "function")
        callback(false);
    }
  });
};
/*------------------微信相关 end---------------------*/

/*------------------keyvaluestore start---------------------*/
as.setRedisKeyValue = function (key, value, callback) {
  var redisOp = {
    "param": {
      "valueKey": key,
      "value": value
    },
    "success": function (res) {
      var bool = res.code == "180001";
      if (typeof callback == "function") callback(bool);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(false);
    }
  };
  as.redis.set(redisOp);
};
as.getRedisKeyValue = function (key, callback) {
  var redisOp = {
    "param": {
      "valueKey": key
    },
    "success": function (res) {
      if (res.code == "181001") {
        if (typeof callback == "function") callback(res["returnMap"][key]);
      } else {
        if (typeof callback == "function") callback(null);
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  };
  as.redis.get(redisOp);
};
as.getRedisList = function (key, callback) {
  var redisOp = {
    "param": {
      "valueKey": key
    },
    "success": function (res) {
      if (res.code == "181001") {
        if (typeof callback == "function") callback(res["returnMap"]);
      } else {
        if (typeof callback == "function") callback(null);
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  };
  as.redis.getList(redisOp);
};
/*------------------keyvaluestore end-----------------------*/

/*------------------自定义函数 start---------------------*/
//单语句查询
as.queryFun = function (funName, data, callback) {
  as.func.runFunction(funName, {
    "param": data,
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
//插入,修改,多语句查询
as.queryFunV2 = function (funName, data, callback) {
  as.func.runFunctionV2(funName, {
    "param": data,
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
/*------------------自定义函数 end---------------------*/

/*------------------抽奖相关 start---------------------*/
//抽奖
as.gameLottery = function (callback) {
  as.rand.rand({
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback({
        "result": false
      });
    }
  });
};
//时间戳格式化(YYYY-mm-dd)
as.timestampFormat = function (timestamp) {
  var myDate = new Date();
  if (timestamp) myDate.setTime(timestamp);
  var year = myDate.getFullYear();
  var month = myDate.getMonth() + 1;
  if (month < 10) month = "0" + month;
  var day = myDate.getDate();
  if (day < 10) day = "0" + day;

  var format = "";
  format += year + "-" + month + "-" + day;
  return format;
};
/*------------------抽奖相关 end-----------------------*/

/*------------------协作相关 start---------------------*/
//从当前链接中获取邀请码 hdp_cooperation_id
as.getCodeFromCurrentUrl = function (callback) {
  as.co.getCodeFromCurrentUrl(function (cooperationId) {
    if (typeof callback == "function") callback(cooperationId);
  });
};
//根据邀请码重置分享链接
as.cooperationSetShareLink = function (resourceId, desc) {
  if (resourceId != "") {
    if (as.shareLink.indexOf("?") > 0) {
      var link = as.shareLink + "&hdp_cooperation_id=" + resourceId;
    } else {
      var link = as.shareLink + "?hdp_cooperation_id=" + resourceId;
    }
    as.setShare(link, "", desc, "");
  }
};
//生成邀请码
as.insertResourceId = function (jsonStr, callback) {
  if (typeof (jsonStr) != 'string') {
    jsonStr = JSON.stringify(jsonStr);
  }
  as.co.uploadAppCooperationInfo({
    "param": {
      "jsonStr": jsonStr
    },
    "success": function (res) {
      if (res && res.success) {
        if (typeof callback == "function") callback(res.content);
      } else {
        if (typeof callback == "function") callback("");
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback("");
    }
  });
};
//判断当前邀请码状态,分辨邀请者身份
as.checkResourceId = function (resourceId, callback) {
  as.co.checkAppCooperationInfoSelfOrNot({
    "param": {
      "resourceId": resourceId
    },
    "success": function (res) {
      if (res && res.success) {
        //res.content :"not exist"非邀请链接;"true"自己的分享链接;"false"他人的分享链接
        if (typeof callback == "function") callback(res.content);
      } else {
        if (typeof callback == "function") callback("not exist");
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback("not exist");
    }
  });
};
//读取用户所有邀请码
as.getResourceId = function (callback) {
  as.co.queryCurrentUserAppCooperationInfoIdList({
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback([]);
    }
  });
};
//读取当前邀请码信息
as.getUserInfoByResourceId = function (resourceId, callback) {
  as.co.queryCurrentAppCooperationInfo({
    "param": {
      "resourceId": resourceId
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
//为邀请码点赞
as.addPraise = function (resourceId, callback) {
  as.co.praise({
    "param": {
      "resourceId": resourceId
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(false);
    }
  });
};
//读取邀请码的点赞数
as.getPraise = function (resourceId, callback) {
  as.co.getPraiseRecordTotalByResourceId({
    "param": {
      "resourceId": resourceId
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(0);
    }
  });
};
//判断用户是否为邀请码点赞
as.checkUserPraise = function (resourceId, callback) {
  as.co.checkCurrentUserPraiseOrNot({
    "param": {
      "resourceId": resourceId
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(false);
    }
  });
};
as.getPraiseLog = function (resourceId, page, size, callback) {
  as.co.queryPraiseRecordListByResourceId({
    "param": {
      "resourceId": resourceId,
      "page": page,
      "size": size
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback([]);
    }
  });
};
//为邀请码评论
as.addComment = function (resourceId, content, callback) {
  as.co.comment({
    "param": {
      "resourceId": resourceId,
      "content": content,
      "parentId": "",
      "remark": ""
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
//评论列表
as.queryCommentList = function (resourceId, page, size, callback) {
  as.co.queryAppCooperationInfoCommentRecordList({
    "param": {
      "resourceId": resourceId,
      "page": page,
      "size": size,
      "ascending": false
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback([]);
    }
  });
};
//读取邀请码评论数
as.queryCommentCount = function (resourceId, callback) {
  as.co.getAppCooperationInfoCommentRecordTotal({
    "param": {
      "resourceId": resourceId
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(0);
    }
  });
};
//当前用户对邀请码的评论总数
as.queryCommentCountByUser = function (resourceId, callback) {
  as.co.getCurrentUserAppCooperationInfoCommentRecordTotal({
    "param": {
      "resourceId": resourceId
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(0);
    }
  });
};
/*------------------协作相关 end-----------------------*/

/*------------------排行榜相关 start---------------------*/
/*
 * 提交成绩
 *  rankName  : 排行榜名字
 *  score     : 游戏分数
 *  spendTime : 游戏耗时
 */
as.rankSubmitScore = function (score, spendTime, callback) {
  as.rank.saveRankScore({
    "param": {
      "rankName": as.rankName,
      "score": score,
      "spendTime": spendTime
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
//查询排行榜(包含当前用户的排行记录)
as.rankQueryRankList = function (page, size, callback) {
  as.rank.queryRankList({
    "param": {
      "rankName": as.rankName,
      "selfInclude": true,
      "page": page,
      "size": size
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
//查询当前用户排名
as.rankQueryUserRankRecord = function (callback) {
  as.rank.queryUserRankRecord({
    "param": {
      "rankName": as.rankName
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
//查询当前用户的记录
as.rankQueryRankHistory = function (callback) {
  as.rank.queryRankHistory({
    "param": {
      "rankName": as.rankName
    },
    "success": function (res) {
      console.log(res, "rankQueryUserRankRecord success");
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      console.log(res.response, "rankQueryUserRankRecord error");
      if (typeof callback == "function") callback(null);
    }
  });
};
/*------------------排行榜相关 end-----------------------*/

/*------------------派加接口相关 start---------------------*/
//读取用户积分
as.getIntegral = function (callback) {
  as.piplus.readUserIntegral({
    "success": function (res) {
      if (res && res.integral) {
        if (typeof callback == "function") callback(res.integral);
      } else {
        if (typeof callback == "function") callback(0);
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback(0);
    }
  });
};
//判断当前用户是否会员
as.checkMember = function (callback) {
  as.piplus.isMember({
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback({
        "isMember": false,
        "integral": 0
      });
    }
  });
};
//查询当前用户会员信息
as.readMember = function (callback) {
  as.piplus.readMember({
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback({
        "status": false
      });
    }
  });
};
//同步会员信息
as.commonSaveUserInfo = function (user_name, mobile, province, city, area, address, birthday, tags, callback) {
  as.piplus.commonSaveUserInfo({
    "param": {
      "user_name": user_name,
      "mobile": mobile,
      "province": province,
      "city": city,
      "area": area,
      "address": address,
      "birthday": birthday,
      "tags": tags
    },
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback({
        "status": false
      });
    }
  });
};
//获取省份
as.getProvinces = function (callback) {
  as.piplus.getProvinces({
    "success": function (res) {
      if (res.http_status && res.errmsg == "success") {
        if (typeof callback == "function") callback(res.data);
      } else {
        if (typeof callback == "function") callback([]);
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback([]);
    }
  });
};
//获取城市
as.getCity = function (regionId, callback) {
  as.piplus.getCity({
    "param": {
      "regionId": regionId
    },
    "success": function (res) {
      if (res.http_status && res.errmsg == "success") {
        if (typeof callback == "function") callback(res.data);
      } else {
        if (typeof callback == "function") callback([]);
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback([]);
    }
  });
};
//获取区域
as.getArea = function (regionId, callback) {
  as.piplus.getCity({
    "param": {
      "regionId": regionId
    },
    "success": function (res) {
      if (res.http_status && res.errmsg == "success") {
        if (typeof callback == "function") callback(res.data);
      } else {
        if (typeof callback == "function") callback([]);
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback([]);
    }
  });
};
/*------------------派加接口相关 end-----------------------*/

/*------------------图片路径转换 start---------------------*/
as.getJpgCdnUrl = function (imgUrl, callback) {
  as.jpgCdn.getJpgCDNUrl({
    "param": {
      "imgUrl": imgUrl
    },
    "success": function (res) {
      if (res && res.success) {
        if (typeof callback == "function") callback(res.content);
      } else {
        if (typeof callback == "function") callback(null);
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
as.getCdnImg = function (imgName, callback) {
  if (typeof callback == "function")
    callback(as.jpgCdn.getCDNImg(imgName));
};
as.designImg = function (imgName, height, callback) {
  if (typeof callback == "function")
    callback(as.jpgCdn.designImg(imgName, height));
};
/*------------------图片路径转换 end-----------------------*/

/*------------------上传照片相关 start---------------------*/
as.uploadBase64 = function (base64, callback) {
  as.file.uploadBase64(base64, as.AppID, {
    "success": function (res) {
      var obj = {
        "result": true,
        "data": res
      };
      if (typeof callback == "function") callback(obj);
    },
    "error": function (res) {
      if (typeof callback == "function") callback({
        "result": false
      });
    }
  });
};
/*------------------上传照片相关 end-----------------------*/

/*------------------微信语音 start---------------------*/
//开始录音
as.startRecord = function (callback) {
  if (typeof wx != "undefined" && wx != void 0) {
    var completeFn = function (res) {
      if (res["errMsg"] == "startRecord:ok") {
        if (typeof callback == "function") callback(true);
      }
    }

    wx.startRecord({
      cancel: function () {
        alert('用户拒绝授权录音');
        if (typeof callback == "function") callback(false);
      },
      complete: completeFn,
    });
    // if (typeof callback == "function") callback(true);
  } else {
    if (typeof callback == "function") callback(false);
  }
};
//停止录音
as.stopRecord = function (callback) {
  if (typeof wx != "undefined" && wx != void 0) {
    wx.stopRecord({
      success: function (res) {
        if (typeof callback == "function") callback(res.localId);
      }
    });
  } else {
    if (typeof callback == "function") callback("");
  }
};
//上传语音到微信服务器
as.uploadVoice = function (localId, callback) {
  if (typeof wx != "undefined" && wx != void 0 && localId != "") {
    wx.uploadVoice({
      "localId": localId, // 需要上传的音频的本地ID,由stopRecord接口获得
      "isShowProgressTips": 1, // 默认为1,显示进度提示
      "success": function (res) {
        if (typeof callback == "function") callback(res.serverId);
      }
    });
  } else {
    if (typeof callback == "function") callback("");
  }
};
//下载微信服务语音到本地
as.downloadVoice = function (serverId, callback) {
  if (typeof wx != "undefined" && wx != void 0 && serverId != "") {
    wx.downloadVoice({
      "serverId": serverId, // 需要下载的音频的服务器端ID,由uploadVoice接口获得
      "isShowProgressTips": 1, // 默认为1,显示进度提示
      "success": function (res) {
        if (res && res.localId) {
          if (typeof callback === "function") callback(res.localId);
        } else {
          if (typeof callback === "function") callback("");
        }
      }
    });
  } else {
    if (typeof callback === "function") callback("");
  }
};

//保存录音
as.saveUserVoice = function (vid, serverId, callback) {
  as.wxMultimedia.record({
    "param": {
      "vId": vid,
      "serverId": serverId
    },
    "success": function (res) {
      if (res && res.code == 10000) {
        if (typeof callback == "function") callback(true);
      } else {
        if (typeof callback == "function") callback(false);
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback(false);
    }
  });
};
//读取单个录音
as.getUserVoice = function (vid, callback) {
  try {
    as.wxMultimedia.get({
      "param": {
        "vId": vid
      },
      "success": function (res) {
        if (typeof callback == "function") callback(res);
      },
      "error": function (res) {
        if (typeof callback == "function") callback(null);
      }
    });
  } catch (e) {
    if (typeof callback == "function") callback(null);
  }
};

//播放声音
as.playVoice = function (localId, voiceStatus, voiceUrl, serverId, callback) {
  if (localId != "") {
    as.playRecord(localId, function () {
      if (typeof callback == "function") callback(true, null);
    });
  } else if ((voiceStatus == "CONVERT_SUCCESS" || voiceStatus == 6) && voiceUrl != "") {
    var dom = document.getElementsByTagName("body")[0];
    var nDiv = document.createElement("div");
    nDiv.style.width = "0px";
    nDiv.style.height = "0px";
    nDiv.style.position = "absolute";
    var sound = document.createElement("audio");
    sound.src = voiceUrl;
    //sound.preload= "preload";
    //sound.src = src;
    nDiv.appendChild(sound);
    dom.appendChild(nDiv);
    sound.addEventListener("ended", function () {
      if (typeof callback === "function") callback(true, null);
    }, false);
    sound.play();
  } else if (serverId != "") {
    as.downloadVoice(serverId, function (res) {
      as.playRecord(res, function () {
        if (typeof callback == "function") callback(true, res);
      });
    });
  } else {
    if (typeof callback === "function") callback(false, null);
  }
};
//播放录音(微信)
as.playRecord = function (localId, callback) {
  if (typeof wx != "undefined" && wx != void 0 && localId != "") {
    wx.playVoice({
      localId: localId // 需要播放的音频的本地ID,由stopRecord接口获得
    });

    wx.onVoicePlayEnd({
      success: function (res) {
        if (typeof callback === "function") callback(true);
      }
    });
  } else {
    if (typeof callback === "function") callback(false);
  }
};
//停止播放录音(微信)
as.stopVoice = function (localId) {
  if (typeof wx != "undefined" && wx != void 0 && localId != "") {
    wx.stopVoice({
      localId: localId
    });
  }
};
/*------------------微信语音 end---------------------*/

/*------------------其它 start---------------------*/
/*
 * tableName 要存的表的名字
 * data 为字典结构
 * 例如 data = {}
 *    data["key"] = value;
 */
as.saveTable = function (tableName, value, callback) {
  var table = HDP.getTable(tableName);
  for (var key in value) {
    table.set(key, value[key]);
  }
  table.save({
    "success": function (res) {
      if (typeof callback == "function") callback(res);
    },
    "error": function (res) {
      if (typeof callback == "function") callback(null);
    }
  });
};
/*------------------其它 end-----------------------*/

/*------------------ 以下为定制化接口 ---------------------*/
as.bizInterface = null;
//多奖池抽奖
as.bizManyLottery = function (appId, callback) {
  if (as.bizInterface == null) {
    as.bizInterface = HDP.getBizInterface();
  }

  if (appId == undefined || appId == null || appId == "") {
    if (typeof callback == "function") callback({
      "result": false
    });
  }

  as.bizInterface.manyLottery({
    "param": {
      "appId": appId
    },
    "success": function (res) {
      if (res && res.success && res.content) {
        if (typeof callback == "function") callback(res.content);
      } else {
        if (typeof callback == "function") callback({
          "result": false
        });
      }
    },
    "error": function (res) {
      if (typeof callback == "function") callback({
        "result": false
      });
    }
  });
};

// module.exports = as;