123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- var getConfigUrl = path +"/watero/config/get";
- var jssdkSuccess = true;
- if (window.hiddenAllWechatMenu == null) {
- window.hiddenAllWechatMenu = false;
- }
- window.wxFriend = null;
- if (window.repleFlag) {
-
- window.wxFriend = window.repleWxData;
- } else {
-
- window.wxFriend = {
- "appId": "",
- "imgUrl":'https://s.iamberry.com/watero/images/shop/index.jpg',
- "link":"https://s.iamberry.com/watero/wechat/index.html",
- "desc":"Watero水时代商城,开启优雅生活",
- "title":"Watero水时代商城,好水,好茶,生活不将就!",
- "netError":"您的网络异常,请刷新重试!如多次刷新无效,请向我们反应 ~",
- "shareTimeSuccess":"这里是分享朋友圈后调用的文字",
- "shareTimeCancel":"这里是取消分享给朋友圈后调用的文字",
- "shareAppSuccess":"这里是分享好友后调用的文字",
- "shareAppCancel":"这里是取消分享给好友后调用的文字"
- };
- }
- window.wechatAddr = {
- "status":false,
- "statusMsg":"失败时信息",
- "detailInfo":"详细地址",
- "postalCode":"邮编",
- "userName":"收货人",
- "userTel":"收货人电话",
- "nationalCode":"收货地址国家码"
- };
- incoldeJSFile("//res.wx.qq.com/open/js/jweixin-1.1.0.js");
- getConfig();
- function getConfig(){
- $.ajax({
- type: 'get', url: getConfigUrl, data: {appid: "", url: location.href,"date":new Date().getTime()}, dataType: 'json', timeout: 10000, context: $('body'),
- success: function(data){setConfig(data);},
- error: function(xhr, type){
- getConfig();
- mui.alert('网络异常,请刷新重试,否则某些功能不能使用!')
- }
- });
- }
- function setConfig(config){
- wx.config({
- debug: false,
- appId: config.appId,
- timestamp: config.timestamp,
- nonceStr: config.nonceStr,
- signature: config.signature,
- jsApiList: [
- 'checkJsApi',
- 'onMenuShareTimeline',
- 'onMenuShareAppMessage',
- 'hideMenuItems',
- 'showMenuItems'
- ]
- });
- wx.ready(function(){
- wxReadySuccess();
- });
- wx.error(function(res){
- wxReadyError();
- });
- }
- function wxReadySuccess() {
- window.jssdkSuccess = true;
- shareMessage();
- wx.getNetworkType({success: function (res) {}});
- if (window.hiddenAllWechatMenu) {
- wx.showMenuItems({
- menuList: [
- ]
- });
- wx.hideMenuItems({
- menuList: [
- "menuItem:copyUrl",
- "menuItem:openWithSafari",
- "menuItem:originPage",
- "menuItem:share:email",
- "menuItem:dayMode",
- "menuItem:setFont",
- "menuItem:nightMode",
- "menuItem:share:qq",
- "menuItem:dayMode",
- "menuItem:exposeArticle",
- "menuItem:nightMode",
- "menuItem:openWithQQBrowser",
- "menuItem:share:QZone",
- "menuItem:favorite",
- "menuItem:share:facebook",
- "menuItem:share:appMessage",
- "menuItem:share:timeline"
- ]
- });
- } else {
- wx.showMenuItems({
- menuList: [
- "menuItem:share:appMessage",
- "menuItem:share:timeline"
- ]
- });
- wx.hideMenuItems({
- menuList: [
- "menuItem:copyUrl",
- "menuItem:openWithSafari",
- "menuItem:originPage",
- "menuItem:share:email",
- "menuItem:dayMode",
- "menuItem:setFont",
- "menuItem:nightMode",
- "menuItem:share:qq",
- "menuItem:dayMode",
- "menuItem:exposeArticle",
- "menuItem:nightMode",
- "menuItem:openWithQQBrowser",
- "menuItem:share:QZone",
- "menuItem:favorite",
- "menuItem:share:facebook"
- ]
- });
- }
- }
- function wxReadyError() {
-
- }
- function shareMessage(title, message) {
- title = title || wxFriend.title;
- message = message || wxFriend.desc;
- wx.onMenuShareTimeline({
- title: title, link: wxFriend.link, imgUrl: wxFriend.imgUrl,
- success: function () {
- if (wxFriend.shareAppSuccess != null && wxFriend.shareAppSuccess != "") {
-
- }
- },
- cancel: function () {
- if (wxFriend.shareTimeCancel != null && wxFriend.shareTimeCancel != "") {
-
- }
- }
- });
- wx.onMenuShareAppMessage({
- title: title, desc: message, link: wxFriend.link, imgUrl: wxFriend.imgUrl,
- success: function () {
- if (wxFriend.shareAppSuccess != null && wxFriend.shareAppSuccess != "") {
-
- }
- },
- cancel: function () {
- if (wxFriend.shareTimeCancel != null && wxFriend.shareTimeCancel != "") {
-
- }
- }
- });
- }
- function wechatPay(str, paySuccessCallBack, payCancelCallBack) {
- if (typeof WeixinJSBridge == "undefined"){
- alert("非微信浏览器!无法发起微信支付请求!");
- return;
- }
- var obj = JSON.parse("{" + str + "}");
- WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
- if(res.err_msg=='get_brand_wcpay_request:ok'){
- paySuccessCallBack
- }else{
- payCancelCallBack
- }
- });
- }
- if (typeof WeixinJSBridge == "undefined"){
- if( document.addEventListener ){
- document.addEventListener('WeixinJSBridgeReady', wechatPay, false);
- }else if (document.attachEvent){
- document.attachEvent('WeixinJSBridgeReady', wechatPay);
- document.attachEvent('onWeixinJSBridgeReady', wechatPay);
- }
- }
- function editAddrV0(config) {
- WeixinJSBridge.invoke('editAddress', {"appId" : config.appId, "scope" : "jsapi_address", "signType" : "SHA1", "addrSign" : config.addrSign, "timeStamp" : config.timestamp, "nonceStr" : config.nonceStr},
- function(res) {
- if ("edit_address:ok" == res.err_msg) {
- var address = res.proviceFirstStageName + "-" + res.addressCitySecondStageName + "-" + res.addressCountiesThirdStageName + "-" + res.addressDetailInfo;
- wechatAddr.status = true;
- wechatAddr.detailInfo = address;
- wechatAddr.postalCode = res.addressPostalCode;
- wechatAddr.userName = res.userName;
- wechatAddr.userTel = res.telNumber;
- return wechatAddr;
- } else if ("edit_address:fail" == res.err_msg) {
- wechatAddr.statusMsg = "您没有选择收货地址!";
- return wechatAddr;
- } else {
- wechatAddr.statusMsg = "操作过时,请刷新重试!";
- return wechatAddr;
- }
- }
- );
- }
- function editAddrV1(successCallback, errorCallback) {
- if (!window.jssdkSuccess) {
- mui.alert("错误啦 ~~ 请刷新重试!");
- return;
- }
- wx.openAddress({
- success: successCallback,
- cancel: errorCallback
- });
- }
- function incoldeJSFile(jsUrl) {
- var typeHand = document.getElementsByTagName('head').item(0);
- var typeScript= document.createElement("script");
- typeScript.type = "text/javascript";
- typeScript.src=jsUrl;
- typeHand.appendChild(typeScript);
- }
|