当前位置: 首页>>代码示例>>Java>>正文


Java SendMessageToWX.Req方法代码示例

本文整理汇总了Java中com.tencent.mm.opensdk.modelmsg.SendMessageToWX.Req方法的典型用法代码示例。如果您正苦于以下问题:Java SendMessageToWX.Req方法的具体用法?Java SendMessageToWX.Req怎么用?Java SendMessageToWX.Req使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.tencent.mm.opensdk.modelmsg.SendMessageToWX的用法示例。


在下文中一共展示了SendMessageToWX.Req方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shareToWX

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
/**
 * @param flag
 * 0 发送到会话
 * 1 发送到朋友圈
 */
private int shareToWX(int flag){
    String text = mDetailItem.getUserName()+"说: "+mDetailItem.getRantContent()+" " + "\n目前有"+mDetailItem.getCommentList().size()+"人围观,来凑个热闹吧!";
    final IWXAPI iwxapi = WXAPIFactory.createWXAPI(this, getString(R.string.app_id));
    iwxapi.registerApp(getString(R.string.app_id));
    if(!iwxapi.isWXAppInstalled()){
        Toast.makeText(this, "你还没有安装微信", Toast.LENGTH_SHORT).show();
        return 0;
    }

    WXWebpageObject webpage = new WXWebpageObject();
    webpage.webpageUrl = getString(R.string.ip_server)+"rant.action?rantId="+mDetailItem.getRantId();
    final WXMediaMessage msg = new WXMediaMessage(webpage);
    msg.title = "Rant社区";
    msg.description = text;

    final SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.scene = flag;
    final Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    msg.setThumbImage(logo);
    req.message = msg;
    iwxapi.sendReq(req);
    return 1;
}
 
开发者ID:shawnsky,项目名称:RantApp,代码行数:30,代码来源:RantActivity.java

示例2: shareWeb

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
public static void shareWeb(Context context,String title,String desc,String url,@Scene int scene){
    if (!checkForSupport(context)) return;
    WXWebpageObject webPage = new WXWebpageObject();
    webPage.webpageUrl = url;
    WXMediaMessage msg = new WXMediaMessage(webPage);
    msg.title = title;
    msg.description = desc;
    Bitmap thumb = BitmapFactory.decodeResource(context.getResources(), R.mipmap.app_icon_64);
    msg.thumbData = bmpToByteArray(thumb);

    // 如果分享到朋友圈需要校验是否支持
    if (scene == SendMessageToWX.Req.WXSceneTimeline && !checkTimeLine(context)) return;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction(scene);
    req.message = msg;
    req.scene = scene;
    boolean sendReq = api.sendReq(req);
}
 
开发者ID:WeGdufe,项目名称:MovingGdufe-Android,代码行数:20,代码来源:ShareUtils.java

示例3: shareText

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
@Override
protected void shareText(final ShareParamText params) throws ShareException {
    String text = params.getContent();
    if (TextUtils.isEmpty(text)) {
        throw new InvalidParamException("Content is empty or illegal");
    }

    WXTextObject textObj = new WXTextObject();
    textObj.text = text;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = text;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("textshare");
    req.message = msg;
    req.scene = getShareType();
    Log.d(TAG, "start share text");
    shareOnMainThread(req);
}
 
开发者ID:Bilibili,项目名称:BiliShare,代码行数:22,代码来源:BaseWxShareHandler.java

示例4: sendMsgToWx

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
private void sendMsgToWx(WXMediaMessage msg, int shareTarget, String sign) {
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction(sign);
    req.message = msg;
    req.scene = getShareToWhere(shareTarget);
    boolean sendResult = mWxApi.sendReq(req);
    if (!sendResult) {
        mOnShareListener.onFailure(new SocialException("sendMsgToWx失败,可能是参数错误"));
    }
}
 
开发者ID:chendongMarch,项目名称:SocialSdkLibrary,代码行数:11,代码来源:WxPlatform.java

示例5: shareText

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
public static void shareText(Context context, String scene) {

        //注册微信
        registerWX(context);
        //构建文本分享消息并发送分享
        WXTextObject wxTextObject = new WXTextObject();
        wxTextObject.text = "你好";

        WXMediaMessage message = new WXMediaMessage();
        message.mediaObject = wxTextObject;
        message.description ="随便逛逛";

        //构造一个REQ
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = buildTransaction("text");
        req.message = message;

        if (scene.equalsIgnoreCase("session")) {
            req.scene = SendMessageToWX.Req.WXSceneSession;
        } else if (scene.equalsIgnoreCase("timeline")) {
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
        } else if (scene.equalsIgnoreCase("favorite")) {
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
        }

        //调用API接口
        api.sendReq(req);

    }
 
开发者ID:haihaio,项目名称:AmenWeather,代码行数:30,代码来源:WXEntryActivityUtils.java

示例6: sendMessage

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
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);
}
 
开发者ID:beanu,项目名称:smart-farmer-android,代码行数:9,代码来源:WxShareInstance.java

示例7: shareText

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
public static void shareText(String text, SharePlace sharePlace) {
    WXTextObject wxTextObject = new WXTextObject();
    wxTextObject.text = text;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = wxTextObject;
    msg.description = text;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = WechatPayTools.getCurrTime();

    req.message = msg;
    switch (sharePlace) {
        case Friend:
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;
        case Zone:
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
        case Favorites:
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
            break;
    }

    if (iwxapi != null) {
        iwxapi.sendReq(req);
    } else {
        throw new NullPointerException("请先调用WechatShare.init()方法");
    }
}
 
开发者ID:vondear,项目名称:RxTools,代码行数:31,代码来源:WechatShareTools.java

示例8: shareImage

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
public static void shareImage(Bitmap bitmap, SharePlace sharePlace) {
    WXImageObject wxImageObject = new WXImageObject(bitmap);
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = wxImageObject;

    Bitmap thumbBmp = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
    bitmap.recycle();
    msg.thumbData = RxImageTool.bitmap2Bytes(thumbBmp, Bitmap.CompressFormat.PNG);

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = WechatPayTools.getCurrTime();

    req.message = msg;
    switch (sharePlace) {
        case Friend:
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;
        case Zone:
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
        case Favorites:
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
            break;
    }

    if (iwxapi != null) {
        iwxapi.sendReq(req);
    } else {
        throw new NullPointerException("请先调用WechatShare.init()方法");
    }
}
 
开发者ID:vondear,项目名称:RxTools,代码行数:32,代码来源:WechatShareTools.java

示例9: shareMusic

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
public static void shareMusic(WechatShareModel shareModel, SharePlace sharePlace) {
    WXMusicObject wxMusicObject = new WXMusicObject();
    wxMusicObject.musicUrl = shareModel.getUrl();

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = wxMusicObject;
    msg.title = shareModel.getTitle();
    msg.description = shareModel.getDescription();

    msg.thumbData = shareModel.getThumbData();

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = WechatPayTools.getCurrTime();
    req.message = msg;

    switch (sharePlace) {
        case Friend:
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;
        case Zone:
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
        case Favorites:
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
            break;
    }

    if (iwxapi != null) {
        iwxapi.sendReq(req);
    } else {
        throw new NullPointerException("请先调用WechatShare.init()方法");
    }
}
 
开发者ID:vondear,项目名称:RxTools,代码行数:34,代码来源:WechatShareTools.java

示例10: shareVideo

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
public static void shareVideo(WechatShareModel shareModel, SharePlace sharePlace) {
    WXVideoObject wxVideoObject = new WXVideoObject();
    wxVideoObject.videoUrl = shareModel.getUrl();

    WXMediaMessage msg = new WXMediaMessage(wxVideoObject);
    msg.title = shareModel.getTitle();
    msg.description = shareModel.getDescription();

    msg.thumbData = shareModel.getThumbData();

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = WechatPayTools.getCurrTime();
    req.message = msg;

    switch (sharePlace) {
        case Friend:
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;
        case Zone:
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
        case Favorites:
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
            break;
    }

    if (iwxapi != null) {
        iwxapi.sendReq(req);
    } else {
        throw new NullPointerException("请先调用WechatShare.init()方法");
    }
}
 
开发者ID:vondear,项目名称:RxTools,代码行数:33,代码来源:WechatShareTools.java

示例11: shareURL

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
public static void shareURL(WechatShareModel shareModel, SharePlace sharePlace) {
    WXWebpageObject webpageObject = new WXWebpageObject();
    webpageObject.webpageUrl = shareModel.getUrl();

    WXMediaMessage msg = new WXMediaMessage(webpageObject);
    msg.title = shareModel.getTitle();
    msg.description = shareModel.getDescription();

    msg.thumbData = shareModel.getThumbData();

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = WechatPayTools.getCurrTime();
    req.message = msg;

    switch (sharePlace) {
        case Friend:
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;
        case Zone:
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
        case Favorites:
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
            break;
    }

    if (iwxapi != null) {
        iwxapi.sendReq(req);
    } else {
        throw new NullPointerException("请先调用WechatShare.init()方法");
    }
}
 
开发者ID:vondear,项目名称:RxTools,代码行数:33,代码来源:WechatShareTools.java

示例12: shareOnMainThread

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
private void shareOnMainThread(final SendMessageToWX.Req req) {
    doOnMainThread(new Runnable() {
        @Override
        public void run() {
            postProgressStart();
            boolean result = mIWXAPI.sendReq(req);
            if (!result && getShareListener() != null) {
                getShareListener().onError(getShareMedia(), BiliShareStatusCode.ST_CODE_SHARE_ERROR_SHARE_FAILED, new ShareException("sendReq failed"));
            }
        }
    });
}
 
开发者ID:Bilibili,项目名称:BiliShare,代码行数:13,代码来源:BaseWxShareHandler.java

示例13: sendRequest2Wechat

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
private static void sendRequest2Wechat(WXMediaMessage msg, boolean toTimeline) {
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = String.valueOf(System.currentTimeMillis());// 请求标识
    req.message = msg;
    req.scene = toTimeline ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;

    sWXApi.sendReq(req);
}
 
开发者ID:ChaosLeong,项目名称:FxcnBeta,代码行数:9,代码来源:WXApiProvider.java

示例14: share

import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
public void share(final JSONObject params, final ModuleResultListener listener)
        throws JSONException {
    final IWXAPI api = getWXAPI();

    if (api == null) {
        callbackError(301101, ERROR_WECHAT_NOT_INITED, listener);
    }

    // check if installed
    if (!api.isWXAppInstalled()) {
        callbackError(301201, ERROR_WECHAT_NOT_INSTALLED, listener);
    }

    final SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction();

    switch (params.getIntValue(KEY_ARG_SCENE)) {
        case SCENE_SESSION:
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case SCENE_TIMELINE:
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;

        case SCENE_FAVORITE:
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
            break;

        default:
            req.scene = SendMessageToWX.Req.WXSceneSession;
    }

    Runnable shareRunnable = new Runnable() {
        @Override
        public void run() {
            try {
                req.message = buildSharingMessage(params);
            } catch (JSONException e) {
                Log.e(TAG, "Failed to build sharing message.", e);
                callbackError(301301, "Failed to build sharing message.", listener);
            }

            if (api.sendReq(req)) {
                Log.i(TAG, "Message has been called successfully.");

                mAsyncListener = new AsyncListener() {
                    @Override
                    public void onSuccess(JSONObject result) {
                        listener.onResult(result);
                    }

                    @Override
                    public void onError(int code, String msg) {
                        callbackError(code, msg, listener);
                    }
                };
            } else {
                Log.i(TAG, "Message has been called unsuccessfully.");
                callbackError(301302, "Unknown error", listener);
            }
        }
    };

    Thread shareThread = new Thread(shareRunnable);
    shareThread.start();
}
 
开发者ID:natjs,项目名称:nat-wechat,代码行数:68,代码来源:WechatModule.java


注:本文中的com.tencent.mm.opensdk.modelmsg.SendMessageToWX.Req方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。