微信公众号开发接口参数调用。

/**
*
* @param obj 需要浏览的对象
* @constructor
*/

//http://qydev.weixin.qq.com/wiki/index.php?title=%E9%A6%96%E9%A1%B5 说明
//http://203.195.235.76/jssdk/ demo
function WxPicView(obj) {
var aa = [];
var i = 0;
var src = [];
var json = null;
aa = $(obj);
for (i = 0; i < aa.length; i++) {
src[i] = $(obj).eq(i).attr("src"); //把所有的src存到数组里
}
$(obj).live("click", function () {
var index = $(obj).index(this);
imagePreview($(obj).eq(index).attr("src"), src);
});
}

function imagePreview(curSrc, srcList) {
//这个检测是否参数为空
if (!curSrc || !srcList || srcList.length == 0) {
return;
}
//这个使用了微信浏览器提供的JsAPI 调用微信图片浏览器
WeixinJSBridge.invoke(‘imagePreview‘, {
‘current‘: curSrc,
‘urls‘: srcList
});
}
/**
* 导航
* @param lat 经度
* @param lng 纬度
* @param name 名称
* @param address 地址
* @constructor
*/
function OpenMapLocation(lat, lng, name, address) {
try {
lat = parseFloat(lat);
lng = parseFloat(lng);
wx.openLocation({
latitude: lat,
longitude: lng,
name: name,
address: address,
scale: 14
});
} catch (e) {
window.location.href = " http://apis.map.qq.com/tools/routeplan/eword=" + name + "&epointx=" + lng + "&epointy=" + lat + "&navibutton=2?referer=myapp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77";
}
}

/**
* 两地距离
* @param lat1
* @param lng1
* @param lat2
* @param lng2
* @returns {*}
*/
function getFlatternDistance(lat1, lng1, lat2, lng2) {
lat1 = Number(lat1);
lat2 = Number(lat2);
lng1 = Number(lng1);
lng2 = Number(lng2);
console.log(lat1 + "==" + lng1 + "==" + lat2 + "==" + lng2);
var f = getRad((lat1 + lat2) / 2);
var g = getRad((lat1 - lat2) / 2);
var l = getRad((lng1 - lng2) / 2);

var sg = Math.sin(g);
var sl = Math.sin(l);
var sf = Math.sin(f);

var s, c, w, r, d, h1, h2;
var a = EARTH_RADIUS;
var fl = 1 / 298.257;

sg = sg * sg;
sl = sl * sl;
sf = sf * sf;

s = sg * (1 - sl) + (1 - sf) * sl;
c = (1 - sg) * (1 - sl) + sf * sl;

w = Math.atan(Math.sqrt(s / c));
r = Math.sqrt(s * c) / w;
d = 2 * w * a;
h1 = (3 * r - 1) / 2 / c;
h2 = (3 * r + 1) / 2 / s;
var re = (Math.round(d * (1 + fl * (h1 * sf * (1 - sg) - h2 * (1 - sf) * sg))) / 1000);
if (isNaN(re)) return "未知距离";
if (re > 10000) return "未知距离";
return re.toFixed(2) + " km";
}
function wxInitial(obj, fn) {
//授权
obj.url = document.location.href;
try {
//Wtxt("正在定位");
$.ajax({
url: "/getsign.action",
type: "post",
data: obj,
success: function (data) {
//$(".windowcenter2").remove();
wx.config({
debug: false,
appId: obj.appid,
timestamp: 1421142450,
nonceStr: ‘Wm3WZYTPz0wzccnW‘,
signature: data.sign,
jsApiList: [
"getLocation", "openLocation", "onMenuShareTimeline", "onMenuShareAppMessage",
"onMenuShareQQ", "onMenuShareWeibo", "onMenuShareQZone"
]
});
}, error: function () {
// closeDialog();
if ($.isFunction(fn)) {
fn();
}
}

});

wx.error(function (res) {
// closeDialog();
if ($.isFunction(fn)) {
fn();
}
// alert(JSON.stringify(res));
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
//istrue =false;
});
} catch (e) {
istrue = true;
}
return istrue;
}
/**
* 定位
* @param obj appid: SHOPSET["appid_" + mchid],
inter: "‘getLocation‘",
secrect: SHOPSET["secrect_" + mchid]
* @param fn
*/
function wxGetPosition(obj, fn) {
try {
wxInitial(obj, fn);
wx.ready(function () {
wx.getLocation({
type: ‘wgs84‘, // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入‘gcj02‘
success: function (res) {
latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
console.log(latitude + "," + longitude);
// return latitude+","+longitude;
if ($.isFunction(fn)) {
fn();
}
}
});
})

} catch (e) {
// return latitude+","+longitude;
}
}

/**
* 分享到朋友圈
* @param titleInfo
* @param descInfo
* @param linkInfo
* @param imgUrlInfo
* @param json
* @param fn
* @constructor
*/
function SetMenuShareTimeline(titleInfo, descInfo, linkInfo, imgUrlInfo, json, fn) {
wx.onMenuShareTimeline({
title: descInfo,
desc: descInfo,
link: linkInfo,
imgUrl: imgUrlInfo,
trigger: function (res) {

},
success: function (res) { //成功分享执行事件
if ($.isFunction(fn)) {
fn(json);
}
},
cancel: function (res) {
alert(‘已取消分享‘);
},
fail: function (res) {
alert(‘分享出错‘);
}
});
SetMenuShareAppMessage(titleInfo, descInfo, linkInfo, imgUrlInfo, json, fn);
}

function SetMenuShareAppMessage(titleInfo, descInfo, linkInfo, imgUrlInfo, json, fn) {
wx.onMenuShareAppMessage({
title: titleInfo,
desc: descInfo,
link: linkInfo,
imgUrl: imgUrlInfo,
trigger: function (res) {
},
success: function (res) {
if ($.isFunction(fn)) {
fn(json);
}
},
cancel: function (res) {
alert(‘已取消分享‘);
},
fail: function (res) {
alert(‘分享出错‘);
}
});
}

微信公众号开发接口参数调用。

上一篇:EXPLAIN sql优化方法(1) 添加索引


下一篇:Zabbix 使用企业微信公众号发送报警短信