本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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失败,可能是参数错误"));
}
}
示例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);
}
示例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);
}
示例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()方法");
}
}
示例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()方法");
}
}
示例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()方法");
}
}
示例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()方法");
}
}
示例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()方法");
}
}
示例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"));
}
}
});
}
示例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);
}
示例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();
}