微信开发,调用js-SDK接口

微信开发,调用js-SDK接口
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<style>

</style>
</head>
<body>
<h1>微信</h1>
<p>UX1wyEikfZC4NW1c7drZlHHaLMc3VhhTMEYt3Qu8BMYaFgrlboJtckZTEdMwPZCJom7xuEN5Hji_gUM_YMC6xBN5Av5Cner4_HJsMlNgPfDZjcyQhYCoQB-sd-cn-JXuZFJfACAHNR</p>
<a href="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx00630f07f5fe0589&secret=33cc2acfbafd5492b1a17aeebe3106b2">链接</a>
<a href="https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=BzQWoLGstPtgiVDNJ891EQbfG13b-zqyxsNTEpQnDwYfM03yQ6Ny_oyBshHStZJV1qAsTUhc6ZuxU87-66od4m5MeUf4wFaIbRCTpKS7QllnGiy_2mLJC-VwflKyEdtmAGQbAGANTD">语义接口</a>
<a href="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=UX1wyEikfZC4NW1c7drZlHHaLMc3VhhTMEYt3Qu8BMYaFgrlboJtckZTEdMwPZCJom7xuEN5Hji_gUM_YMC6xBN5Av5Cner4_HJsMlNgPfDZjcyQhYCoQB-sd-cn-JXuZFJfACAHNR&type=jsapi">jsapi</a>
<button onclick="checkJson()">点击</button>
<!--<button id="onMenuShareTimeline">onMenuShareTimeline</button>-->
<button onclick="checkSign()">123</button>
<button onclick="chackC()">677787</button>
<button onclick="checkApi()">checkApi</button>
<script src="js/jquery-1.11.3.js"></script>
<script>

function checkJson(){
$.ajax({
type: "post",
url:"https://api.weixin.qq.com/semantic/semproxy/search?access_token=otZynt6CfBlj_bO4FDb3k7PbHJgVsZ_JF4LCSd4YaLfVgTB0gPbvEuaNsoKlPSF0GCShtRNBCtzjSTS7BxC3MrvrbLpnhC0qTfR1y-fWeLPBjeeYsZ6K7Vv7QLjCvOtaUVJfAIALMA",
data:{
"query":"1",
"city":"2",
"category": "flight,hotel",
"appid":"wx00630f07f5fe0588",
"uid":"123456"
},
success: function(msg){
alert( "Data Saved: " + msg );
}
})
}
var nonceStrR;
var timestampR;
var signatureR;
function checkSign(){
$.ajax({
type: "post",
url:"query.do",
data:{
JSticket:"kgt8ON7yVITDhtdwci0qea_7zWUVeegljlIDSsYEEIVMeXQ_b1daZhw5yifCIGt5FLHdlydZn1pkp3cYlA8c4Q",
url:"http://www.iok.la/"//调用绑定的域名
// sign('jsapi_ticket', 'http://example.com')
},
success: function(msg){
// var data1=JSON.stringify(msg);
var data1 =msg;
console.log(data1);
nonceStrR=data1.nonceStr;
timestampR=data1.timestamp;
signatureR=data1.signature;
console.log(data1.signature);
}
})
}
function chackC(){
wx.config({
debug:true,
appId:"",
timestamp:timestampR,
nonceStr:nonceStrR,
signature:signatureR,
jsApiList:[
'checkJsApi',
'onMenuShareAppMessage',
'onMenuShareTimeline',
]
});
}

wx.ready(function () {
alert("成功");
});
wx.error(function(res){
console.log(JSON.stringify(res));
});
function checkApi(){
wx.checkJsApi({
jsApiList:[
'checkJsApi',
'onMenuShareAppMessage',
'onMenuShareTimeline',
],
success:function(res){
console.log(JSON.stringify(res))
}
})
}
</script>
</body>
</html>
服务器端
/**
* Created by on 2016/7/12.
*/
var myexpress = require("./server/node_modules/express");
var app = myexpress();
app.set("port",80);
/*配置express*/
app.configure(function(){
app.use(myexpress.logger("dev")); //日志模块,写在核心模块上面,dev是开发者模式,日志会打印在console
/*------------核心模块*/
app.use(myexpress.bodyParser());
app.use(myexpress.methodOverride());
app.use(app.router);
app.use(myexpress.static(__dirname));
/*------------核心模块完*/
//浏览器上的图标
app.use(myexpress.favicon(__dirname+""));
app.use(myexpress.errorHandler()); //错误信息打印在控制台上
});
app.listen(app.get("port"),function(){
console.log("express正在监听端口:"+app.get("port"));
});
//注意需要引用sign.js
var sign = require('./js/sign.js');
app.post("/query.do",function(request,response){
console.log(request.body);
console.log(sign(request.body.JSticket,request.body.url));
var data =sign(request.body.JSticket,request.body.url);
var data1={
nonceStr:data.nonceStr,
timestamp:data.timestamp,
signature:data.signature
};
console.log(data1);
response.send(data1);
});


posted @ 2016-12-15 11:06  黑黑哈哈  阅读(988)  评论(0编辑  收藏  举报