2017微信地址共享DEMO 最新可用DEMO
微信就是个坑!!!接触过各种系统平台对接,但这辈子估计都碰不上比微信更坑的了!!!
文档API各种低级错误。
DEMO都是错的,说好的参数小写,demo里面是大写。
SHA1传参加密的样例,用他给的串,怎么都加密都加不出他的结果。
甭管什么异常,调失败了就一条,写个错误码的枚举能费多少时间?微信大爷!
文档里漏到的条件更不用说了。
文档没有的条件1,要开通微信支付。
文档没有的条件2,要开启共享收货地址。(现在已经没这个设置了)
文档没有的条件3,必须在设置的授权目录之下发起API调用。
http://res.wx.qq.com/open/js/jweixin-1.1.0.js
http://res.wx.qq.com/open/js/jweixin-1.1.0.js
http://res.wx.qq.com/open/js/jweixin-1.1.0.js
重要的地方说三次, 微信的公开文档里还是写的v1.0.0 ,MD, 这么大公司,文档版本控制就这个水平,如果你饮用了V1.0.0 的js.
会提示根本没有wx.openAddress 的定义。
在V1.1.0 里openAddress 和editAddress 其实是一回事,都是通过js打开你自己的微信地址,
再说一点,这个功能在微信web 开发工具里没法调试,会提示不支持,或者该SDK不存在,再次问候它NN, 微信自己做的开发工具,连这个提示都不给准确一点。
下面是完整代码, 至于签名那几个 字段的获取,网上已经很多封装好的方法可以调用,这里就不重复了。
我是用的VS .net 开发, 在cs 代码里给这几个属性赋值了,在aspx 里直接引用即可。 如果在使用过程中遇到其它问题,欢迎联系探讨。
--------------------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="shareaddress.aspx.cs" Inherits="MxWeiXinPF.Web.weixin.shareaddress" %>
<%@ Import Namespace="MxWeiXinPF.Common" %>
<!DOCTYPE html>
<html>
<head runat="server" />
<title>共享地址测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<script type="text/javascript" src="/scripts/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1" />
<style type="text/css">
body {
margin: 0;
padding: 0;
background: #eae9e6;
}
body, p, table, td, th {
font-size: 14px;
font-family: helvetica,Arial,Tahoma;
}
h1 {
font-family: Baskerville,HelveticaNeue-Bold,helvetica,Arial,Tahoma;
}
a {
text-decoration: none;
color: #385487;
}
.container {
}
.title {
}
#content {
padding: 30px 20px 20px;
color: #111;
background: #f7f2ed;
}
.seeAlso {
padding: 15px 20px 30px;
}
.headpic div {
margin: 20px 0 0;
}
.headpic img {
display: block;
}
.title h1 {
font-size: 22px;
font-weight: bold;
padding: 0;
margin: 0;
line-height: 1.2;
color: #1f1f1f;
}
.title p {
color: #aaa;
font-size: 12px;
margin: 5px 0 0;
padding: 0;
font-weight: bold;
}
.pic {
margin: 20px 0;
}
.articlecontent img {
display: block;
clear: both;
margin: 5px auto;
}
.articlecontent p {
text-indent: 2em;
font-family: Georgia,helvetica,Arial,Tahoma;
line-height: 1.4;
font-size: 16px;
margin: 20px 0;
}
.seeAlso h3 {
font-size: 16px;
color: #a5a5a5;
}
.seeAlso ul {
margin: 0;
padding: 0;
}
.seeAlso li {
font-size: 16px;
list-style-type: none;
border-top: 1px solid #ccc;
padding: 2px 0;
}
.seeAlso li a {
border-bottom: none;
display: block;
line-height: 1.1;
padding: 13px 0;
}
.clr {
clear: both;
height: 1px;
overflow: hidden;
}
.fontSize1 .title h1 {
font-size: 20px;
}
.fontSize1 .articlecontent p {
font-size: 14px;
}
.fontSize1 .weibo .nickname, .fontSize1 .weibo .comment {
font-size: 11px;
}
.fontSize1 .moreOperator {
font-size: 14px;
}
.fontSize2 .title h1 {
font-size: 22px;
}
.fontSize2 .articlecontent p {
font-size: 16px;
}
.fontSize2 .weibo .nickname, .fontSize2 .weibo .comment {
font-size: 13px;
}
.fontSize2 .moreOperator {
font-size: 16px;
}
.fontSize3 .title h1 {
font-size: 24px;
}
.fontSize3 .articlecontent p {
font-size: 18px;
}
.fontSize3 .weibo .nickname, .fontSize3 .weibo .comment {
font-size: 15px;
}
.fontSize3 .moreOperator {
font-size: 18px;
}
.fontSize4 .title h1 {
font-size: 26px;
}
.fontSize4 .articlecontent p {
font-size: 20px;
}
.fontSize4 .weibo .nickname, .fontSize4 .weibo .comment {
font-size: 16px;
}
.fontSize4 .moreOperator {
font-size: 20px;
}
.jumptoorg {
display: block;
margin: 16px 0 16px;
}
.jumptoorg a {
}
.moreOperator a {
color: #385487;
}
.moreOperator .share {
border-top: 1px solid #ddd;
}
.moreOperator .share a {
display: block;
border: 1px solid #ccc;
border-bottom-style: solid;
background: #f8f7f1;
color: #000;
}
.moreOperator .share a span {
display: block;
padding: 10px 10px;
text-align: center;
border-top: 1px solid #eee;
border-bottom: 1px solid #eae9e3;
font-weight: bold;
}
.moreOperator .share a:hover,
.moreOperator .share a:active {
background: #efedea;
}
@@media only screen and (-webkit-min-device-pixel-ratio: 2) {
}
</style>
//
<body>
<div>
<form name="form1" id="form1" method="post" action="">
<input type="button" id="getaddress2" onclick="show();" value="得到地址方式2" /><br />
<br>
<input name="address1" id="address1" type="text" size=20 /><br />
<input name="address2" id="address2" type="text" size=20/><br />
<input name="address3" id="address3" type="text" size=20/><br />
<input name="detail" id="detail" type="text" size=30 /><br />
</form>
<div id="divinfo"></div>
<div id="resvalues">aaaaaaaaS</div>
<script>
wx.config({
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '<%=fxModel.appid%>', // 必填,公众号的唯一标识
timestamp:'<%=fxModel.timestamp%>', // 必填,生成签名的时间戳
nonceStr: '<%=fxModel.nonce%>', // 必填,生成签名的随机串
signature: '<%=fxModel.signature%>',// 必填,签名,见附录1
jsApiList: ['editAddress',
'openAddress'
] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function(){
//
});
function show(){
wx.openAddress({
success: function (res) {
alert(JSON.stringify(res));
document.form1.address1.value = res.provinceName;
document.form1.address2.value = res.cityName;
document.form1.address3.value = res.countryName;
document.form1.detail.value = res.detailInfo;
},
cancel: function (res) {
alert('用户取消拉出地址');
},
fail: function (res) {
alert(JSON.stringify(res));
}
})
};
wx.error(function(res){
//
});
wx.checkJsApi({
jsApiList: ['editAddress',
'getLatestAddress',
'openAddress'
], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function(res) {
// 以键值对的形式返回,可用的api值true,不可用为false
alert(JSON.stringify(res));
// 如:{"editAddress":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
})
</script>
</body>
</html>
浙公网安备 33010602011771号