這幾天研究了一下這個微信公眾平臺的開發(fā)的問題
在使用chooseImage接口調(diào)用獲取到了圖片的時候一直顯示不出來酣衷,百度了一些帖子結(jié)果都不是很好穿仪,后來終于研究出來怎么顯示出來了啊片,現(xiàn)在寫出來做一個備份
使用微信JSDK的時候遇到的一些問題
在配置S接口安全域名的時候需要用一級域名玖像,不能使用二級域名,并且不能帶http 或者h(yuǎn)ttps
如我的測試上傳圖片網(wǎng)址是
http://robertfly.applinzi.com/php_jssdk/jssdkdemo.php
在定義域名的時候要使用
applinzi.com
<pre>
//html里的主要代碼
<body ontouchstart="">
上傳圖片的測試
圖像接口
<span class="desc">拍照或從手機(jī)相冊中選圖接口</span>
<button class="btn btn_primary" id="chooseImage" onclick="chooseImg_Opinion()">chooseImage</button>
<span>圖片預(yù)覽</span>
<div id="photo"></div>
</body>
</br>
//js里的主要代碼
<script>
wx.ready(function () {
//自動執(zhí)行的
wx.checkJsApi({
jsApiList: [
'chooseImage',
],
success: function (res) {
// alert(JSON.stringify(res));
// alert(JSON.stringify(res.checkResult.getLocation));
// if (res.checkResult.getLocation == false) {
// alert('你的微信版本太低笤昨,不支持微信JS接口握恳,請升級到最新的微信版本!');
// return;
// }
}
});
});
wx.error(function (res) {
alert(res.errMsg);
});
function chooseImg_Opinion() {
wx.chooseImage({
success: function (res) {
showImgs_Opinion(res);
}
});
}
function showImgs_Opinion(res) {
//主要是這一塊的代碼
var parent = document.getElementById('photo');
var div = document.createElement("div");
//設(shè)置 div 屬性崇裁,如 id
div.setAttribute("id", "imgDiv");
var _html="";
for(var i in res.localIds){
var photoSrc=res.localIds[i];
_html=_html+'<br>圖片'+i+':<img src="'+photoSrc+'" height="200" width="200" />\n';
}
div.innerHTML = _html;
parent.appendChild(div);
</script>
</pre>
相關(guān)網(wǎng)址:
githup上代碼的網(wǎng)址:
https://github.com/robert1202/MpWeiXin_Robert/tree/master/ChooseImage
演示效果的網(wǎng)址:
http://robertfly.applinzi.com/php_jssdk/jssdkdemo.php
我的微信個人訂閱號,敬請關(guān)注 共同學(xué)習(xí)
順便打一個廣告
使用這個新浪云 可以使用一定時長免費(fèi)的域名空間葛峻,如果你只是為了學(xué)習(xí)這個開發(fā)巴比,還是可以先用用的,點(diǎn)擊注冊 實(shí)名認(rèn)證成功后可各獲得200云豆
「新浪云福利」1000云豆免費(fèi)領(lǐng)腰耙!低成本铲球、免運(yùn)維、靈活稼病、安全穩(wěn)定,輕松應(yīng)對業(yè)務(wù)爆發(fā)式增長援制,一起來用吧芍瑞!
注冊地址:http://t.cn/Rti8Tq3