suchen

Heim  >  Fragen und Antworten  >  Hauptteil

javascript - 微信chooseImage接口部分机型选择图片后莫名其妙的跳转其他页面

微信调用接口开启debug模式都是正常的,但是部分用户访问时程序到了chooseImage会跳转上上一页面或者关闭当前页回单微信菜单界面弹出提示拍照按钮。
以下是我程序该方法调用:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

<code>var origin = location.origin;

if(ctx != ""){

    origin = origin + ctx + "/";

}

$.ajax({

    type: "POST",

    url: ctx + '/weChat/getSignatureInfo',

    data: {pageUrl:location.href.split('#')[0]},

    dataType: "json",

    success: function(data){

        var configData = {

            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。

            appId: data.appid, // 必填,公众号的唯一标识

            timestamp: data.timestamp, // 必填,生成签名的时间戳

            nonceStr: data.nonceStr, // 必填,生成签名的随机串

            signature: data.signature,// 必填,签名,见附录1

            jsApiList: ['chooseImage','uploadImage']// 必填,需要使用的JS接口列表,所有JS接口列表见附录2

        };

        // 加载微信SDK引入js

   //     $.getScript('http://res.wx.qq.com/open/js/jweixin-1.0.0.js').done(function() {

            wx.config(configData);

            wx.ready(function () {

                 

                var uploadImgs =null;

                    wx.chooseImage({

                    count: 1, // 默认9

                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有

                    sourceType: [ 'camera'], // 可以指定来源是相册还是相机,默认二者都有

                     success: function (res) {

                         alert("dep1");

                         uploadImgs = res.localIds;

                         alert("dep2");

                         

                       

                       var localId = uploadImgs.pop();

                       alert("dep3");

                        wx.uploadImage({

                              localId:localId, // 需要上传的图片的本地ID,由chooseImage接口获得

                              isShowProgressTips: 1, // 默认为1,显示进度提示

                              success: function (res) {

                                alert("dep4");

                                  var serverId = res.serverId; // 返回图片的服务器端ID

                                alert("dep5");

                                     if(serverId.indexOf("wxLocalResource://")>=0){

              $("#errorMessage").text("图片上传失败,请重新上传!");

               $('.phone_layer_box').show();

               return;

           }

                                   sessionStorage.setItem("imgSrcA",uploadImgs);

                       $("#img_upload_site_A").html("<img src=\'"+localId+"\'  class='img_upload_site'  />");

                       $("#imgAs").val(localId);

                       $("#imgA").attr("value",serverId);

                              }

                          });

                     }

                   });

                     

            });

            wx.error(function(res){

                // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。

                // alert(res.errMsg);

            });

     //   });

       }

});</code>

PHPzPHPz2896 Tage vor915

Antworte allen(1)Ich werde antworten

  • 伊谢尔伦

    伊谢尔伦2017-04-11 13:22:05

    经同事沟通,jssdk验证由开始的触发就验证调整为进入页面初始化验证,在接下来的测试中有一部小米2s依旧不行另一台可以。

    Antwort
    0
  • StornierenAntwort