xu-li / cordova-plugin-wechat

A cordova plugin, a JS version of Wechat SDK
1.22k stars 508 forks source link

安卓发送文件失败 “发送请求失败” #574

Open crapthings opened 4 years ago

crapthings commented 4 years ago

Cordova.Plugin.Wechat 2.9.0

03-05 19:03:36.001 5708 22328 D Cordova.Plugin.Wechat: Start building message. 03-05 19:03:36.002 5708 22328 D Cordova.Plugin.Wechat: Start downloading file at 03-05 19:03:36.226 5708 22328 D Cordova.Plugin.Wechat: File was downloaded and saved at /storage/emulated/0/cache/. 03-05 19:03:36.227 5708 22328 D Cordova.Plugin.Wechat: File was downloaded and cached to /storage/emulated/0/cache/5ba Cordova.Plugin.Wechat: Message has been sent unsuccessfully.

看样子文件已经下载回沙箱了,但是在弹出好友窗之前就提示“发送请求失败”

Wechat.share({
      message: {
        title: doc.filename,

        description: ``,

        media: {
          type: Wechat.Type.FILE,
          file: `https://www.nikon.com.cn/manual/D7000.pdf`,
        },
      },
      scene: Wechat.Scene.SESSION,
    }, function shareSuccess () {}, function shareFailed(err) {
      alert(err)
    });
crapthings commented 4 years ago

我把那个链接换成 百度 logo 没事

https://www.baidu.com/img/bd_logo1.png

是用容量限制吗?白名单?

怎么知道发送的限制呢?

crapthings commented 4 years ago

发送成功的log

03-06 10:54:21.411 15452 15526 D Cordova.Plugin.Wechat: File was downloaded and saved at /storage/emulated/0/cache/1583390735624_469_680x682.png.
03-06 10:54:21.411 15452 15526 D Cordova.Plugin.Wechat: File was downloaded and cached to /storage/emulated/0/cache/1583390735624_469_680x682.png.
03-06 10:54:21.414 15452 15526 D MicroMsg.SDK.WXMsgImplComm: check signature:308202eb30820254a00302010202044d36f7a4300d06092a864886f70d01010505003081b9310b300906035504061302383631123010060355040813094775616e67646f6e673111300f060355040713085368656e7a68656e31353033060355040a132c54656e63656e7420546563686e6f6c6f6779285368656e7a68656e2920436f6d70616e79204c696d69746564313a3038060355040b133154656e63656e74204775616e677a686f7520526573656172636820616e6420446576656c6f706d656e742043656e7465723110300e0603550403130754656e63656e74301e170d3131303131393134333933325a170d3431303131313134333933325a3081b9310b300906035504061302383631123010060355040813094775616e67646f6e673111300f060355040713085368656e7a68656e31353033060355040a132c54656e63656e7420546563686e6f6c6f6779285368656e7a68656e2920436f6d70616e79204c696d69746564313a3038060355040b133154656e63656e74204775616e677a686f7520526573656172636820616e6420446576656c6f706d656e742043656e7465723110300e0603550403130754656e63656e7430819f300d06092a864886f70d010101050003818d0030818902818100c05f34b231b083fb1323670bfbe7bdab40c0c0a6efc87ef2072a1ff0d60cc67c8edb0d0847f210bea6cbfaa241be70c86daf56be08b723c859e52428a064555d80db448cdcacc1aea2501eba06f8bad12a4fa49d85cacd7abeb68945a5cb5e061629b52e3254c373550ee4e40cb7c8ae6f7a8151ccd8df582d446f39ae0c5e930203010001300d06092a864886f70d0101050500038181009c8d9d7f2f908c42081b4c764c377109a8b2c70582422125ce545842d5f520aea69550b6bd8bfd94e987b75a3077eb04ad341f481aac266e89d3864456e69fba13df018acdc168b9a19dfd7ad9d9cc6f6ace57c746515f71234df3a053e33ba93ece5cd0fc15f3e389a3f365588a9fcb439e069d3629cd7732a13fff7b891499
03-06 10:54:21.414 15452 15526 D MicroMsg.SDK.WXMsgImplComm: pass
03-06 10:54:21.414 15452 15526 I MicroMsg.SDK.WXApiImplV10: sendReq, req type = 2
03-06 10:54:21.414 15452 15526 D HwFrameworkSecurityPartsFactory: HwFrameworkSecurityPartsFactory in.
03-06 10:54:21.414 15452 15526 I HwFrameworkSecurityPartsFactory: add HwFrameworkSecurityPartsFactory to memory.
03-06 10:54:21.420  1263  1790 W AlarmManager: WAKEUP alarm trigger action = ALARM_ACTION(28780) package name is: com.eg.android.AlipayGphone tag: *walarm*:ALARM_ACTION(28780) window:0 originWhen:1767524054 when:1767524054 maxWhen:1767524054
03-06 10:54:21.429  1263  2069 V ActivityManager: Successfully start provider ContentProviderRecord{6bd03f8 u0 com.tencent.mm/.plugin.base.stub.WXCommProvider} launchingApp=null caller pid= 15452
03-06 10:54:21.432  1263  1823 I NetworkPolicy: updateRuleForRestrictBackgroundUL(10154): isForeground=true, isBlacklisted=false, isWhitelisted=true, isRestrictedByAdmin=false, oldRule=0 (NONE), newRule=1 (NONE|ALLOW_METERED), newUidRules=1 (NONE|ALLOW_METERED), oldUidRules=0 (NONE), mRestrictBackground=false
03-06 10:54:21.438  1263 10178 V BroadcastQueue: Finished with ordered broadcast BroadcastRecord{7328abf u0 ALARM_ACTION(28780)}
03-06 10:54:21.438 15452 15526 I MicroMsg.SDK.WXApiImplV10: getTokenFromWX token is OpenSdkToken@1583463261431
03-06 10:54:21.443 15452 15526 D MicroMsg.SDK.MMessageAct: send, targetPkgName = com.tencent.mm, targetClassName = com.tencent.mm.plugin.base.stub.WXEntryActivity
03-06 10:54:21.446  1263 17099 I ActivityTaskManager: START u0 {flg=0x18000000 hwFlg=0x10 cmp=com.tencent.mm/.plugin.base.stub.WXEntryActivity (has extras)} from uid 10559
03-06 10:54:21.447   863   896 D AwareLog: iawared:  decompress gpu mem, pid:29281
03-06 10:54:21.447  1263 17099 I ActivityTaskManager: ActivityRecord info: ActivityInfo{73702b9 com.tencent.mm.plugin.base.stub.WXEntryActivity}
03-06 10:54:21.448  2368  2709 I PG_ash  : front pkg : com.tencent.mm launcher: false
03-06 10:54:21.448  2368  2709 I PG_ash  : above launcher front pkgs: [com.fawuapp, com.tencent.mm]
03-06 10:54:21.449  1263 17099 D ActivityTaskManager: TaskLaunchParamsModifier:task=null activity=ActivityRecord{6d060e9 u0 com.tencent.mm/.plugin.base.stub.WXEntryActivity t-1} display-from-source=0 display-id=0 display-windowing-mode=1
03-06 10:54:21.449  1263 17099 D ActivityTaskManager: TaskLaunchParamsModifier:task=null activity=ActivityRecord{6d060e9 u0 com.tencent.mm/.plugin.base.stub.WXEntryActivity t-1} display-from-source=0 display-id=0 display-windowing-mode=1 activity-options-fullscreen=Rect(0, 0 - 0, 0) inherit-fullscreen non-freeform-display
03-06 10:54:21.450  1263 17099 V ActivityTaskManager: addChild: attaching stackId=2075 to displayId=0 position=7
03-06 10:54:21.450  1263 17099 V ActivityTaskManager: positionChild stackId=2075 to top.
03-06 10:54:21.451  1263 17099 D ActivityTaskManager: TaskLaunchParamsModifier:task=TaskRecord{6b4d2e1 #18758 A=.sdkentry U=0 StackId=2075 sz=0} activity=ActivityRecord{6d060e9 u0 com.tencent.mm/.plugin.base.stub.WXEntryActivity t-1} display-from-task=0 display-id=0 display-windowing-mode=1 activity-options-fullscreen=Rect(0, 0 - 0, 0) inherit-fullscreen non-freeform-display
03-06 10:54:21.452  1263 17099 V ActivityTaskManager: positionChild stackId=2075 to top.
03-06 10:54:21.453  1263 17099 V ActivityTaskManager: addAppToken: AppWindowToken{77557cb token=Token{7a59f5d ActivityRecord{6d060e9 u0 com.tencent.mm/.plugin.base.stub.WXEntryActivity t18758}}} task={taskId=18758 appTokens=[] mdr=false} at 2147483647
03-06 10:54:21.455 15452 15656 E MtaSDK  : [pool-6-thread-1(32855): null:783] - Server response error code:404, error:{"ret":-1, "msg":"invalid appkey"}
03-06 10:54:21.456 15452 15526 D MicroMsg.SDK.MMessageAct: send mm message, intent=Intent { flg=0x18000000 cmp=com.tencent.mm/.plugin.base.stub.WXEntryActivity (has extras) }
03-06 10:54:21.456 15452 15526 I Cordova.Plugin.Wechat: Message has been sent successfully.

发送失败的log

03-06 11:00:53.772 15452 16714 D Cordova.Plugin.Wechat: File was downloaded and saved at /storage/emulated/0/cache/B-1944(2)_C.pdf.
03-06 11:00:53.772 15452 16714 D Cordova.Plugin.Wechat: File was downloaded and cached to /storage/emulated/0/cache/B-1944(2)_C.pdf.
03-06 11:00:53.840 15452 16714 D MicroMsg.SDK.WXMsgImplComm: check signature:308202eb30820254a00302010202044d36f7a4300d06092a864886f70d01010505003081b9310b300906035504061302383631123010060355040813094775616e67646f6e673111300f060355040713085368656e7a68656e31353033060355040a132c54656e63656e7420546563686e6f6c6f6779285368656e7a68656e2920436f6d70616e79204c696d69746564313a3038060355040b133154656e63656e74204775616e677a686f7520526573656172636820616e6420446576656c6f706d656e742043656e7465723110300e0603550403130754656e63656e74301e170d3131303131393134333933325a170d3431303131313134333933325a3081b9310b300906035504061302383631123010060355040813094775616e67646f6e673111300f060355040713085368656e7a68656e31353033060355040a132c54656e63656e7420546563686e6f6c6f6779285368656e7a68656e2920436f6d70616e79204c696d69746564313a3038060355040b133154656e63656e74204775616e677a686f7520526573656172636820616e6420446576656c6f706d656e742043656e7465723110300e0603550403130754656e63656e7430819f300d06092a864886f70d010101050003818d0030818902818100c05f34b231b083fb1323670bfbe7bdab40c0c0a6efc87ef2072a1ff0d60cc67c8edb0d0847f210bea6cbfaa241be70c86daf56be08b723c859e52428a064555d80db448cdcacc1aea2501eba06f8bad12a4fa49d85cacd7abeb68945a5cb5e061629b52e3254c373550ee4e40cb7c8ae6f7a8151ccd8df582d446f39ae0c5e930203010001300d06092a864886f70d0101050500038181009c8d9d7f2f908c42081b4c764c377109a8b2c70582422125ce545842d5f520aea69550b6bd8bfd94e987b75a3077eb04ad341f481aac266e89d3864456e69fba13df018acdc168b9a19dfd7ad9d9cc6f6ace57c746515f71234df3a053e33ba93ece5cd0fc15f3e389a3f365588a9fcb439e069d3629cd7732a13fff7b891499
03-06 11:00:53.841 15452 16714 D MicroMsg.SDK.WXMsgImplComm: pass
03-06 11:00:53.841 15452 16714 I MicroMsg.SDK.WXApiImplV10: sendReq, req type = 2
03-06 11:00:53.847  1263 17101 V ActivityManager: Successfully start provider ContentProviderRecord{6bd03f8 u0 com.tencent.mm/.plugin.base.stub.WXCommProvider} launchingApp=null caller pid= 15452
03-06 11:00:53.849  1263  1823 I NetworkPolicy: updateRuleForRestrictBackgroundUL(10154): isForeground=true, isBlacklisted=false, isWhitelisted=true, isRestrictedByAdmin=false, oldRule=0 (NONE), newRule=1 (NONE|ALLOW_METERED), newUidRules=1 (NONE|ALLOW_METERED), oldUidRules=0 (NONE), mRestrictBackground=false
03-06 11:00:53.854    53    53 W migration/7: type=1400 audit(0.0:35525163): avc: granted { setsched } for pid=53 scontext=u:r:kernel:s0 tcontext=u:r:kernel:s0 tclass=process
03-06 11:00:53.858 15452 16714 I MicroMsg.SDK.WXApiImplV10: getTokenFromWX token is OpenSdkToken@1583463653855
03-06 11:00:53.859 15452 16714 D MicroMsg.SDK.MMessageAct: send, targetPkgName = com.tencent.mm, targetClassName = com.tencent.mm.plugin.base.stub.WXEntryActivity
03-06 11:00:53.862 15452 16714 E JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 2457992)
03-06 11:00:53.862 15452 16714 E MicroMsg.SDK.MMessageAct: send fail, ex = Failure from system
03-06 11:00:53.862 15452 16714 I Cordova.Plugin.Wechat: Message has been sent unsuccessfully.

这里失败说

03-06 11:00:53.862 15452 16714 E JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 2457992)

网上查是文件不能超过1mb,什么情况哦,微信不是最大 10mb 吗

我试验了一下,100kb 文件分享出去了

Wechat.share({
      message: {
        title: 'file-sample_100kB.doc',
        description: `${_.get(Meteor.user(), 'profile.name')}分享的文件`,
        description: `从律方分享了说明书`,
        thumb: _.get(DOCUMENT_TABLE, `${doc.metadata.fileType}.iconUrl`),
        media: {
          type: Wechat.Type.FILE,
          file: `https://file-examples.com/wp-content/uploads/2017/02/file-sample_100kB.doc`,
        },
      },
      scene: Wechat.Scene.SESSION,
    }, function shareSuccess () {}, function shareFailed(err) {
      alert(err)
    });

我觉得问题应该出在这里

https://github.com/xu-li/cordova-plugin-wechat/blob/develop/src/android/Wechat.java#L463

能不能把这个换成本地的路径啊?微信支不支持本地路径然后他就自己上传了

crapthings commented 4 years ago

不太懂原生的东西,我搜到了理论上应该是可以搞一个路径的

https://github.com/ahmedjalal93/VehicleBus/blob/master/com/tencent/mm/sdk/openapi/WXFileObject.java#L29

crapthings commented 4 years ago

@jasonz1987 @xu-li

修改后可以支持 1mb 以上文件了

这边用复制的新方法,用文件路径就可以上传大于 1mb 文件了

case TYPE_WECHAT_SHARING_FILE:
                    WXFileObject fileObject = new WXFileObject();
                    File file = getFileInputStreamUrl(media.getString(KEY_ARG_MESSAGE_MEDIA_FILE));
                    if (file != null) {
                        fileObject.filePath = file.getPath​();
                    }
                    mediaObject = fileObject;
                    break;
protected File getFileInputStreamUrl(String url) {
        File inputStream = null;

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            if (!cordova.hasPermission(ANDROID_WRITE_EXTERNAL_STORAGE)) {
                cordova.requestPermission(this, REQUEST_CODE_ENABLE_PERMISSION, ANDROID_WRITE_EXTERNAL_STORAGE);
            }
        }

        File file = Util.downloadAndCacheFile(webView.getContext(), url);

        if (file == null) {
            Log.d(TAG, String.format("File could not be downloaded from %s.", url));
            return null;
        }

        // url = file.getAbsolutePath();
        inputStream = file;

        Log.d(TAG, String.format("File was downloaded and cached to %s.", file.getAbsolutePath()));

        return inputStream;
    }

https://github.com/crapthings/cordova-plugin-wechat/blob/09956e29adac50089af31a8960ca33059d1b8868/src/android/Wechat.java#L462

https://github.com/crapthings/cordova-plugin-wechat/blob/09956e29adac50089af31a8960ca33059d1b8868/src/android/Wechat.java#L679

coderJCWang commented 1 year ago

这么改完 安卓11 分享异常 楼主有方法解决吗