最近接一个小程序的分享,要求我们app端生成一个图片给用户用微信扫码,本地直接调微信分享小程序链接。根据微信官方api(https://open.weixin.qq.com/)接了小程序,代码如下
//小程序分享 public void shareLocal() { WXMiniProgramObject programObject = new WXMiniProgramObject(); programObject.webpageUrl = "http://qq.com";
//你申请的username和path programObject.userName = "sssssss"; programObject.path = "22222222"; WXMediaMessage mes = new WXMediaMessage(programObject); mes.title = "小程序分享"; mes.description = "扫码打开小程序"; ContentResolver resolver = getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(resolver .openInputStream(uriLocal)); Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, THUMB_SIZE, THUMB_SIZE, true); bitmap.recycle(); mes.thumbData = MyCommonUserUtils.Bitmap2Bytes(scaledBitmap); SendMessageToWX.Req req = new SendMessageToWX.Req(); req.transaction = buildTransaction("webpage"); req.message = mes; req.scene = SendMessageToWX.Req.WXSceneSession; IWXAPI api = WXAPIFactory.createWXAPI(MicroshopQRCodeActivity.this, "wxc25ceaf2882bcf67", false); int wxAppS