com.tencent.mm.sdk.modelmsg.SendMessageToWX Java Examples

The following examples show how to use com.tencent.mm.sdk.modelmsg.SendMessageToWX. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WeChatShareProxy.java    From ESSocialSDK with Apache License 2.0 6 votes vote down vote up
public static void shareComplete(SendMessageToWX.Resp resp) {
    if (null != mCallback) {
        switch (resp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                mCallback.onSuccess();
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                mCallback.onCancel();
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
            default:
                mCallback.onFailure(new Exception("BaseResp.ErrCode.ERR_AUTH_DENIED"));
                break;
        }
    }
}
 
Example #2
Source File: WeChatShareProxy.java    From ESSocialSDK with Apache License 2.0 6 votes vote down vote up
public static void shareToWeChatTimeline(final Context context, final String appId, final String title, final String url,
                                         final String thumbnail, final IWXShareCallback callback) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            WeChatShareProxy.mCallback = callback;
            WXWebpageObject webpage = new WXWebpageObject();
            webpage.webpageUrl = url;
            WXMediaMessage msg = new WXMediaMessage(webpage);
            msg.title = title;
            byte[] thumb = SocialUtils.getHtmlByteArray(thumbnail);
            if (null != thumb)
                msg.thumbData = SocialUtils.compressBitmap(thumb, 32);
            else
                msg.thumbData = SocialUtils.compressBitmap(SocialUtils.getDefaultShareImage(context), 32);

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = SocialUtils.buildTransaction("webpage");
            req.message = msg;
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            WeChat.getIWXAPIInstance(context, appId).sendReq(req);
        }
    }).start();

}
 
Example #3
Source File: WeChatShareProxy.java    From ESSocialSDK with Apache License 2.0 6 votes vote down vote up
public static void shareToWeChat(final Context context, final String appId, final String title, final String desc,
                                 final String url, final String thumbnail, final IWXShareCallback callback) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            WeChatShareProxy.mCallback = callback;
            WXWebpageObject webpage = new WXWebpageObject();
            webpage.webpageUrl = url;
            WXMediaMessage msg = new WXMediaMessage(webpage);
            msg.title = title;
            msg.description = desc;
            byte[] thumb = SocialUtils.getHtmlByteArray(thumbnail);
            if (null != thumb)
                msg.thumbData = SocialUtils.compressBitmap(thumb, 32);
            else
                msg.thumbData = SocialUtils.compressBitmap(SocialUtils.getDefaultShareImage(context), 32);

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = SocialUtils.buildTransaction("webpage");
            req.message = msg;
            req.scene = SendMessageToWX.Req.WXSceneSession;
            WeChat.getIWXAPIInstance(context, appId).sendReq(req);
        }
    }).start();

}
 
Example #4
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
public void shareWebUrlWithIcon(Bitmap icon, String shareUrl, String title, String desc,
                              boolean shareToFriendCircle, IWXShareCallback callback) {
    final String id = buildTransaction("web_url");
    WXWebpageObject webObj = new WXWebpageObject();
    webObj.webpageUrl = shareUrl;
    webObj.extInfo = "this is extInfo";

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = webObj;
    msg.title = title;
    msg.description = desc;
    msg.setThumbImage(icon);

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = id;
    req.message = msg;
    req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline
            : SendMessageToWX.Req.WXSceneSession;

    mCallbackMap.put(req.transaction.hashCode(),callback);
    mWxApi.sendReq(req);
}
 
Example #5
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
/***
 * @param path  the local image path
 */
public void shareImageByPath(String path,String title ,String desc,boolean shareToFriendCircle,IWXShareCallback callback){
    WXImageObject imgObj = new WXImageObject();
    imgObj.setImagePath(path);

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;
    msg.title = title;
    msg.description = desc;

   // Bitmap bmp = BitmapFactory.decodeFile(path);
    Bitmap bmp = new ImageParser(0,0).parseToBitmap(path);
    Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
    bmp.recycle();
    msg.thumbData = Util.bitampToByteArray(thumbBmp);

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("img");
    req.message = msg;
    req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;

    mCallbackMap.put(req.transaction.hashCode(),callback);
    mWxApi.sendReq(req);
}
 
Example #6
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
/**
 *  分享文本
 * @param text
 * @param shareToFriendCircle  是否分享到朋友圈
 */
public void shareText(String text,boolean shareToFriendCircle,IWXShareCallback callback){
    // 初始化一个WXTextObject对象
    WXTextObject textObj = new WXTextObject();
    textObj.text = text;

    // 用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    // 发送文本类型的消息时,title字段不起作用
    // msg.title = "Will be ignored";
    msg.description = text;

    // 构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("text"); // transaction字段用于唯一标识一个请求
    req.message = msg;
    req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;

    mCallbackMap.put(req.transaction.hashCode(),callback);
    // 调用api接口发送数据到微信
    mWxApi.sendReq(req);
}
 
Example #7
Source File: UserInfoActivity.java    From WeGit with Apache License 2.0 6 votes vote down vote up
private void test() {
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    WXImageObject imgObj = new WXImageObject(bmp);

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;

    Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 200, 200, true);
    bmp.recycle();
    msg.thumbData = BitmapUtils.bmpToByteArray(thumbBmp, true);  //

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = System.currentTimeMillis() + "";
    req.message = msg;
    req.scene = SendMessageToWX.Req.WXSceneSession;
    api.sendReq(req);
}
 
Example #8
Source File: WeChatHelper.java    From talk-android with MIT License 5 votes vote down vote up
private void sendTextToWX(String text, boolean isTimeline) {
    WXTextObject textObject = new WXTextObject();
    textObject.text = text;
    WXMediaMessage msg = new WXMediaMessage(textObject);
    msg.description = text;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("text");
    req.message = msg;
    req.scene = isTimeline ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
    wxApi.sendReq(req);
}
 
Example #9
Source File: WXCallbackActivity.java    From ESSocialSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void onResp(BaseResp resp) {
    if (resp instanceof SendAuth.Resp)
        WeChatSSOProxy.authComplete((SendAuth.Resp) resp);
    else if (resp instanceof SendMessageToWX.Resp)
        WeChatShareProxy.shareComplete((SendMessageToWX.Resp) resp);

    finish();
}
 
Example #10
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(SendMessageToWX.Req req) {
    if(req.message == null){
        Object cl = mCallbackMap.get(req.transaction.hashCode());
        if(cl!=null){
            ((IWXShareCallback)cl).onShareFailed("read image to WXMediaMessage.thumbData failed");
            mCallbackMap.clear();
        }
    }else{
        mWxApi.sendReq(req);
    }
    super.onPostExecute(req);
}
 
Example #11
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@Override
protected SendMessageToWX.Req doInBackground(Object... params) {
    final String url = (String) params[0];
    final String title = (String)params[1];
    final String desc = (String)params[2];
    final boolean shareToFriendCircle = (Boolean)params[3];
    final IWXShareCallback callback = (IWXShareCallback)params[4];

    WXImageObject imgObj = new WXImageObject();
    imgObj.imageUrl = url;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;
    msg.title = title;
    msg.description = desc;

    final String transaction = buildTransaction("img");
    mCallbackMap.put(transaction.hashCode(), callback);
    try {
        Bitmap bmp = new ImageParser(0,0).parseToBitmap(IoUtil.getBytesFromStreamAndClose(
                new URL(url).openStream()));
        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
        bmp.recycle();
        msg.thumbData =  Util.bitampToByteArray(thumbBmp);

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = transaction;
        req.message = msg;
        req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline
                : SendMessageToWX.Req.WXSceneSession;
        return req ;
    } catch (IOException e) {
        e.printStackTrace();
    }
    SendMessageToWX.Req req2 = new SendMessageToWX.Req();
    req2.transaction = transaction;
    req2.message = null;
    return req2;
}
 
Example #12
Source File: SharePopWindow.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
/**
 * 分享到微信朋友或者朋友圈
 * @param scene 标记是发送朋友圈还是微信好友
 */
private void share2WeiXin(int scene) {
	if(!api.isWXAppInstalled()) {
		if(scene == SendMessageToWX.Req.WXSceneSession) {
			ToastUtils.showMessageInCenter(context, "您没有安装【微信】\n安装后才能分享到微信好友");
		} else {
			ToastUtils.showMessageInCenter(context, "您没有安装【微信】\n安装后才能分享到朋友圈");
		}
	}
	WXWebpageObject webpage = new WXWebpageObject();
	webpage.webpageUrl = targetUrl + mJoke.getId();
	WXMediaMessage msg = new WXMediaMessage(webpage);
	Bitmap thumb = null;
	switch (mJoke.getType()) {
	case Joke.TYPE_QUSHI:
		msg.title = context.getString(R.string.share_title_qushi);
		msg.description = mJoke.getContent();
		thumb = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
		break;
	case Joke.TYPE_QUTU:
		msg.title = context.getString(R.string.share_title_qutu);
		msg.description = mJoke.getTitle();
		//微信分享缩略图最大不能超过32K,否则无法调开微信界面
		thumb = BitmapUtil.getThumbBitmapFromCache(mJoke.getImgUrl(), 100, 100);
		break;
	case Joke.TYPE_MEITU:
		msg.title = context.getString(R.string.share_title_meitu);
		msg.description = mJoke.getTitle();
		thumb = BitmapUtil.getThumbBitmapFromCache(mJoke.getImgUrl(), 100, 100);
		break;
	}
	msg.thumbData = ImgUtil.bmpToByteArray(thumb, true);
	
	SendMessageToWX.Req req = new SendMessageToWX.Req();
	req.transaction = buildTransaction("webpage");
	req.message = msg;
	req.scene = scene;
	api.sendReq(req);
	thumb.recycle();
}
 
Example #13
Source File: ShareByWeixin.java    From ShareSDK with MIT License 5 votes vote down vote up
private void send(Bitmap bitmap) {
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.message = buildWXMediaMessage(bitmap);
    if (channel == ShareConstant.SHARE_CHANNEL_WEIXIN_FRIEND) {
        req.scene = SendMessageToWX.Req.WXSceneSession;
    } else if (channel == ShareConstant.SHARE_CHANNEL_WEIXIN_CIRCLE) {
        req.scene = SendMessageToWX.Req.WXSceneTimeline;
    }
    api.sendReq(req);
}
 
Example #14
Source File: WxShareInstance.java    From ShareUtil with Apache License 2.0 5 votes vote down vote up
private void sendMessage(int platform, WXMediaMessage message, String transaction) {
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = transaction;
    req.message = message;
    req.scene = platform == SharePlatform.WX_TIMELINE ? SendMessageToWX.Req.WXSceneTimeline
            : SendMessageToWX.Req.WXSceneSession;
    mIWXAPI.sendReq(req);
}
 
Example #15
Source File: WeixinShareApi.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
private static void doShareWebPage(final String url,final String title,final String desc,final String img,final boolean timelined) {
    if(api==null) {
        api= WXAPIFactory.createWXAPI(MainApp.getContext(), APP_ID);
    }

    Bitmap bitmap= ImageUtil.getBitmap(img);
    Bitmap thumb =null;
    if(bitmap!=null){
        thumb=Bitmap.createScaledBitmap(bitmap, 64, 64, true);
    }

    WXWebpageObject webpage = new WXWebpageObject();
    webpage.webpageUrl = url;
    WXMediaMessage msg = new WXMediaMessage(webpage);
    msg.title = title;
    msg.description = desc;

    if(thumb!=null) {
        msg.thumbData = BitmapUtil.bmpToByteArray(thumb, true);
    }else{
        Bitmap thumbIcon = BitmapFactory.decodeResource(MainApp.getInstance().getResources(), R.drawable.icon);
        msg.thumbData = BitmapUtil.bmpToByteArray(thumbIcon, true);
    }

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("webpage");
    req.message = msg;
    req.scene = timelined ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
    api.sendReq(req);
}
 
Example #16
Source File: ShareFragment.java    From Sky31Radio with Apache License 2.0 4 votes vote down vote up
/**
 * 分享给微信好友
 */
private void shareToWechatFriends() {
    this.sendRequestToWX(SendMessageToWX.Req.WXSceneSession);
}
 
Example #17
Source File: ShareFragment.java    From Sky31Radio with Apache License 2.0 4 votes vote down vote up
/**
 * 分享到微信朋友圈
 */
private void shareToWechatMoments() {
    this.sendRequestToWX(SendMessageToWX.Req.WXSceneTimeline);
}
 
Example #18
Source File: ShareFragment.java    From Sky31Radio with Apache License 2.0 4 votes vote down vote up
private void sendRequestToWX(final int scene){
    picasso.load(sharingProgram.getThumbnail())
            .into(new Target() {
                @Override
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    byte[] data = BitmapUtils.encodeToByteArray(bitmap);
                    this.sendRequest(data);
                }

                @Override
                public void onBitmapFailed(Drawable errorDrawable) {
                    this.sendRequest(null);
                }

                @Override
                public void onPrepareLoad(Drawable placeHolderDrawable) {

                }
                private void sendRequest(byte[] thumbData){
                    IWXAPI iwxapi = WXAPIFactory.createWXAPI(getActivity(), BuildConfig.WECHAT_APP_ID, true);
                    iwxapi.registerApp(BuildConfig.WECHAT_APP_ID);

                    WXMusicObject object = new WXMusicObject();
                    object.musicUrl = BuildConfig.APP_DOWNLOAD_URL;
                    object.musicDataUrl = sharingProgram.getAudio().getSrc();
                    object.musicLowBandUrl = sharingProgram.getThumbnail();
                    object.musicLowBandDataUrl = sharingProgram.getThumbnail();
                    WXMediaMessage message = new WXMediaMessage();
                    message.mediaObject = object;
                    message.title = sharingProgram.getTitle();
                    message.description = getString(R.string.tpl_wx_share_description,
                            getString(R.string.app_name),
                            sharingProgram.getAuthor());
                    message.thumbData  = thumbData;

                    SendMessageToWX.Req request = new SendMessageToWX.Req();
                    request.message = message;
                    request.transaction = String.valueOf(System.currentTimeMillis());
                    request.scene = scene;

                    iwxapi.sendReq(request);
                    iwxapi.unregisterApp();
                }
            });

}
 
Example #19
Source File: SharePopWindow.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
	if(mJoke == null) {
		return;
	}
	switch (v.getId()) {
	case R.id.share_weixin:   //微信
		share2WeiXin(SendMessageToWX.Req.WXSceneSession);
		MobclickAgent.onEvent(context, "share_weixin");
		saveShareTimes();
		break;
	case R.id.share_pengyouquan:  //朋友圈
		share2WeiXin(SendMessageToWX.Req.WXSceneTimeline);
		MobclickAgent.onEvent(context, "share_pengyouquan");
		saveShareTimes();
		break;
	case R.id.share_qqfriends:  //QQ好友
		share2QQFriends();
		MobclickAgent.onEvent(context, "share_qq");
		saveShareTimes();
		break;
	case R.id.share_qqzone:  //QQ空间
		share2QZone();
		MobclickAgent.onEvent(context, "share_qqzone");
		saveShareTimes();
		break;
	case R.id.share_qqweibo:  //QQ微博
		share2QQWeibo();
		MobclickAgent.onEvent(context, "share_qqweibo");
		saveShareTimes();
		break;
	case R.id.share_sinaweibo:  //新浪微博
		share2SinaWeibo();
		MobclickAgent.onEvent(context, "share_sina_weibo");
		saveShareTimes();
		break;
	case R.id.share_sms:  //短信
		sendSms();
		MobclickAgent.onEvent(context, "share_sms");
		break;
	case R.id.share_copy:  //复制
		copy();
		MobclickAgent.onEvent(context, "share_copy");
		break;
	case R.id.share_collect:  //收藏
		if(collect == null) {  
			v.setSelected(true);
			collect();
		} else {   //取消收藏
			v.setSelected(false);
			cancelCollect();
		}
		break;
	}
	this.dismiss();
}
 
Example #20
Source File: ShareByWeixin.java    From ShareSDK with MIT License 4 votes vote down vote up
public void shareImg(Bitmap bitmap, OnShareListener listener) {
    if (null == bitmap) {
        if (null != listener) {
            listener.onShare(channel, ShareConstant.SHARE_STATUS_FAILED);
        }
        return;
    }
    if (api.isWXAppInstalled()) {
        if (api.isWXAppSupportAPI()) {
            WXMediaMessage wxMediaMessage = new WXMediaMessage();
            wxMediaMessage.mediaObject = new WXImageObject(bitmap);

            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            while (width * height > THUMB_SIZE * THUMB_SIZE) {
                width /= 2;
                height /= 2;
            }
            Bitmap thumbBmp = Bitmap.createScaledBitmap(bitmap, width, height, true);
            try {
                ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
                thumbBmp.compress(Bitmap.CompressFormat.JPEG, 85, localByteArrayOutputStream);
                wxMediaMessage.thumbData = localByteArrayOutputStream.toByteArray();
                localByteArrayOutputStream.close();
            } catch (Exception e) {

            }

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = String.valueOf(System.currentTimeMillis());
            req.message = wxMediaMessage;
            if (ShareConstant.SHARE_CHANNEL_WEIXIN_FRIEND == channel) {
                req.scene = SendMessageToWX.Req.WXSceneSession;
            } else if (ShareConstant.SHARE_CHANNEL_WEIXIN_CIRCLE == channel) {
                req.scene = SendMessageToWX.Req.WXSceneTimeline;
            }
            api.sendReq(req);
        }
    } else {
        if (null != listener) {
            listener.onShare(channel, ShareConstant.SHARE_STATUS_FAILED);
        }
        ToastUtil.showToast(context, R.string.share_no_weixin_client, true);
    }
}
 
Example #21
Source File: Activity_Result_Combination.java    From MortgageCalculator with Apache License 2.0 4 votes vote down vote up
private void share2WeChat(int flag) {
    if (!wxApi.isWXAppInstalled()) {
        Toast.makeText(Activity_Result_Combination.this, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }

    DecimalFormat df = new DecimalFormat("#,###.0");

    StringBuilder stringBuilder = new StringBuilder("组合贷款\n");
    stringBuilder.append("贷款总额:").append(df.format(mortgage / 10000)).append("万元\n");
    stringBuilder.append("贷款月数:").append(time).append("月\n\n");

    stringBuilder.append("等额本息贷款方式:\n");
    stringBuilder.append("商业还款:").append(oneSumCommString).append("元\n");
    stringBuilder.append("商业利息:").append(oneInterestCommString).append("元\n");
    stringBuilder.append("公积金还款:").append(oneSumHAFString).append("元\n");
    stringBuilder.append("公积金利息:").append(oneInterestHAFString).append("元\n");
    stringBuilder.append("还款总额:").append(onePayString).append("元\n");
    stringBuilder.append("利息总额:").append(oneInterestString).append("元\n\n");

    stringBuilder.append("等额本金贷款方式:\n");
    stringBuilder.append("商业还款:").append(twoSumCommString).append("元\n");
    stringBuilder.append("商业利息:").append(twoInterestCommString).append("元\n");
    stringBuilder.append("公积金还款:").append(twoSumHAFString).append("元\n");
    stringBuilder.append("公积金利息:").append(twoInterestHAFString).append("元\n");
    stringBuilder.append("还款总额:").append(twoPayString).append("元\n");
    stringBuilder.append("利息总额:").append(twoInterestString).append("元\n");

    //初始化一个WXTextObject对象,填写分享的文本内容
    WXTextObject textObj = new WXTextObject();
    textObj.text = stringBuilder.toString();

    //用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = "房贷计算结果";

    //构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    //req.transaction = buildTransaction("这是transaction");				//transaction字段用于唯一标识一个请求
    req.message = msg;

    switch (flag){
        case 0:
            //发送给好友
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case 1:
            //发送到朋友圈
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
    }
    wxApi.sendReq(req);
}
 
Example #22
Source File: Activity_Result.java    From MortgageCalculator with Apache License 2.0 4 votes vote down vote up
private void share2WeChat(int flag) {
    if (!wxApi.isWXAppInstalled()) {
        Toast.makeText(Activity_Result.this, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }

    StringBuilder stringBuilder = new StringBuilder(title + "\n");
    stringBuilder.append("贷款总额:").append(oneLoanSumTextView.getText().toString()).append("\n");
    stringBuilder.append("贷款月数:").append(time).append("月\n\n");

    stringBuilder.append("等额本息贷款方式:\n");
    stringBuilder.append("还款总额:").append(oneSumString).append("元\n");
    stringBuilder.append("支付利息:").append(oneInterestString).append("元\n");
    stringBuilder.append("每月还款:").append(oneMonthPayString).append("元\n\n");

    stringBuilder.append("等额本金贷款方式:\n");
    stringBuilder.append("还款总额:").append(twoSumString).append("元\n");
    stringBuilder.append("支付利息:").append(twoInterestString).append("元\n");
    stringBuilder.append("首月还款:").append(twoFistMonthSum).append("元\n");
    stringBuilder.append("每月递减:").append(twoDeltaMonthSum).append("元\n");

    //初始化一个WXTextObject对象,填写分享的文本内容
    WXTextObject textObj = new WXTextObject();
    textObj.text = stringBuilder.toString();

    //用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = "房贷计算结果";

    //构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    //req.transaction = buildTransaction("这是transaction");				//transaction字段用于唯一标识一个请求
    req.message = msg;

    switch (flag){
        case 0:
            //发送给好友
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case 1:
            //发送到朋友圈
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
    }
    wxApi.sendReq(req);
}
 
Example #23
Source File: Activity_Result_Combination.java    From MortgageCalculator with Apache License 2.0 4 votes vote down vote up
private void share2WeChat(int flag) {
    if (!wxApi.isWXAppInstalled()) {
        Toast.makeText(Activity_Result_Combination.this, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }

    DecimalFormat df = new DecimalFormat("#,###.0");

    StringBuilder stringBuilder = new StringBuilder("组合贷款\n");
    stringBuilder.append("贷款总额:").append(df.format(mortgage / 10000)).append("万元\n");
    stringBuilder.append("贷款月数:").append(time).append("月\n\n");

    stringBuilder.append("等额本息贷款方式:\n");
    stringBuilder.append("商业还款:").append(oneSumCommString).append("元\n");
    stringBuilder.append("商业利息:").append(oneInterestCommString).append("元\n");
    stringBuilder.append("公积金还款:").append(oneSumHAFString).append("元\n");
    stringBuilder.append("公积金利息:").append(oneInterestHAFString).append("元\n");
    stringBuilder.append("还款总额:").append(onePayString).append("元\n");
    stringBuilder.append("利息总额:").append(oneInterestString).append("元\n\n");

    stringBuilder.append("等额本金贷款方式:\n");
    stringBuilder.append("商业还款:").append(twoSumCommString).append("元\n");
    stringBuilder.append("商业利息:").append(twoInterestCommString).append("元\n");
    stringBuilder.append("公积金还款:").append(twoSumHAFString).append("元\n");
    stringBuilder.append("公积金利息:").append(twoInterestHAFString).append("元\n");
    stringBuilder.append("还款总额:").append(twoPayString).append("元\n");
    stringBuilder.append("利息总额:").append(twoInterestString).append("元\n");

    //初始化一个WXTextObject对象,填写分享的文本内容
    WXTextObject textObj = new WXTextObject();
    textObj.text = stringBuilder.toString();

    //用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = "房贷计算结果";

    //构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    //req.transaction = buildTransaction("这是transaction");				//transaction字段用于唯一标识一个请求
    req.message = msg;

    switch (flag){
        case 0:
            //发送给好友
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case 1:
            //发送到朋友圈
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
    }
    wxApi.sendReq(req);
}
 
Example #24
Source File: Activity_Result.java    From MortgageCalculator with Apache License 2.0 4 votes vote down vote up
private void share2WeChat(int flag) {
    if (!wxApi.isWXAppInstalled()) {
        Toast.makeText(Activity_Result.this, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }

    StringBuilder stringBuilder = new StringBuilder(title + "\n");
    stringBuilder.append("贷款总额:").append(oneLoanSumTextView.getText().toString()).append("\n");
    stringBuilder.append("贷款月数:").append(time).append("月\n\n");

    stringBuilder.append("等额本息贷款方式:\n");
    stringBuilder.append("还款总额:").append(oneSumString).append("元\n");
    stringBuilder.append("支付利息:").append(oneInterestString).append("元\n");
    stringBuilder.append("每月还款:").append(oneMonthPayString).append("元\n\n");

    stringBuilder.append("等额本金贷款方式:\n");
    stringBuilder.append("还款总额:").append(twoSumString).append("元\n");
    stringBuilder.append("支付利息:").append(twoInterestString).append("元\n");
    stringBuilder.append("首月还款:").append(twoFistMonthSum).append("元\n");
    stringBuilder.append("每月递减:").append(twoDeltaMonthSum).append("元\n");

    //初始化一个WXTextObject对象,填写分享的文本内容
    WXTextObject textObj = new WXTextObject();
    textObj.text = stringBuilder.toString();

    //用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = "房贷计算结果";

    //构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    //req.transaction = buildTransaction("这是transaction");				//transaction字段用于唯一标识一个请求
    req.message = msg;

    switch (flag){
        case 0:
            //发送给好友
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case 1:
            //发送到朋友圈
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
    }
    wxApi.sendReq(req);
}
 
Example #25
Source File: WXEntryActivity.java    From Android-Application-ZJB with Apache License 2.0 votes vote down vote up
@OnClick({R.id.share_weixin,
            R.id.share_timeline, R.id.share_qzone, R.id.cancel})
    public void onClick(View view) {
        mIsInitialize = true;
        switch (view.getId()) {
//            case R.id.share_sina:
//                mViewModel.share2Weibo(mShareProvider);
//                break;
            case R.id.share_weixin:
                mViewModel.share2Weixin(SendMessageToWX.Req.WXSceneSession, mShareProvider);
                channel = "wechat";
                break;
            case R.id.share_timeline:
                mViewModel.share2Weixin(SendMessageToWX.Req.WXSceneTimeline, mShareProvider);
                channel = "timeline";
                break;
            case R.id.share_qzone:
                //点击qq分享的统计
                StatisticsUtil.onEvent(R.string.click_qq);
                mViewModel.share2QQ(this, mShareProvider);
                channel = "qq";
                break;
            case R.id.cancel:
                finish();
                break;
            default:
                break;
        }
    }