javascript - php 微信開發中圖片長傳的問題?

來源:互聯網
上載者:User
關鍵字 php javascript
大神們,php服務號開發,有沒有好的圖片上傳外掛程式推薦。自己找個圖片上傳外掛程式,端不怎麼支。

回複內容:

大神們,php服務號開發,有沒有好的圖片上傳外掛程式推薦。自己找個圖片上傳外掛程式,端不怎麼支。

這個一般都是用自己的js-sdk外掛程式,的策略是:

配置`js-sdk`,成功後調用介面比如:拍照、圖片選擇、圖片上傳,當然圖片是上傳到伺服器的,然後你需要做的是在程式後端利用上傳返回的`meidia_id`來下載上傳的圖片,這樣就不需要自己找外掛程式了,而且你自己找的外掛程式上也不會支援的;
wx.config({        debug: false, // 開啟偵錯模式,調用的所有api的傳回值會在用戶端alert出來,若要查看傳入的參數,可以在pc端開啟,參數資訊會通過log打出,僅在pc端時才會列印。        appId: '{$appid}', // 必填,公眾號的唯一標識        timestamp: "{$timestamp}", // 必填,產生簽名的時間戳記        nonceStr: '{$noncestr}', // 必填,產生簽名的隨機串        signature: '{$signature}',// 必填,簽名,見附錄1        jsApiList: ['chooseImage','previewImage','uploadImage'] // 必填,需要使用的JS介面列表,所有JS介面列表見附錄2    });    $(".box-fill").each(function(){        var ele = $(this);        $(this).click(function(){            wx.chooseImage({                count: 1, // 預設9                sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,預設二者都有                sourceType: ['album', 'camera'], // 可以指定來源是相簿還是相機,預設二者都有                success: function (res) {                    var localIds = res.localIds; // 返回選定照片的本地ID列表,localId可以作為img標籤的src屬性顯示圖片                    var $imgStr = "";                    ele.html($imgStr);                    wx.uploadImage({                        localId: localIds.toString(), // 需要上傳的圖片的本地ID,由chooseImage介面獲得                        isShowProgressTips: 1, // 預設為1,顯示進度提示                        success: function (res) {                            var serverId = res.serverId; // 返回圖片的伺服器端ID                            uploadServerId(serverId, ele.data('type'));                        }                    });                }            });        })    })    /**     * 上傳服務id,也就是可以在伺服器下載圖片的media_id     * @param serverId     * @param type 上傳圖片類型     */    function uploadServerId(serverId, type){        $.post("{:U('uploadServerId')}", {openId: "{$openid}", serverId: serverId, type: type},function(ret){            if(ret.status == -1){                alert(ret.msg);            }else if(ret.status == 1){                if(ret.finish){                    $(".filters").hide();                }            }else{                alert('請關閉頁面後重新登陸上傳!');            }        })    }

另外,建議你去公眾平台看下js-sdk的開發文檔,因為這涉及到了後端的一些東西,要求部分資訊需要在服務端完成,而不是在前端

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.