本文整理汇总了Java中com.tencent.mm.sdk.openapi.SendMessageToWX类的典型用法代码示例。如果您正苦于以下问题:Java SendMessageToWX类的具体用法?Java SendMessageToWX怎么用?Java SendMessageToWX使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SendMessageToWX类属于com.tencent.mm.sdk.openapi包,在下文中一共展示了SendMessageToWX类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shareText
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void shareText(int shareType, ShareContent shareContent) {
String text = shareContent.getContent();
//初始化一个WXTextObject对象
WXTextObject textObj = new WXTextObject();
textObj.text = text;
//用WXTextObject对象初始化一个WXMediaMessage对象
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = textObj;
msg.description = text;
//构造一个Req
SendMessageToWX.Req req = new SendMessageToWX.Req();
//transaction字段用于唯一标识一个请求
req.transaction = ShareUtil.buildTransaction("textshare");
req.message = msg;
//发送的目标场景, 可以选择发送到会话 WXSceneSession 或者朋友圈 WXSceneTimeline。 默认发送到会话。
req.scene = shareType;
mIWXAPI.sendReq(req);
}
示例2: shareMusic
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void shareMusic(int shareType, ShareContent shareContent) {
WXMusicObject music = new WXMusicObject();
//Str1+"#wechat_music_url="+str2 ;str1是网页地址,str2是音乐地址。
music.musicUrl =shareContent.getURL()+ "#wechat_music_url="+shareContent.getMusicUrl();
WXMediaMessage msg = new WXMediaMessage(music);
msg.title = shareContent.getTitle();
msg.description = shareContent.getContent();
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = ShareUtil.buildTransaction("music");
req.message = msg;
req.scene = shareType;
sendShare(shareContent.getImageUrl(), req);
}
示例3: sendShare
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void sendShare(final String imageUrl, final SendMessageToWX.Req req) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Bitmap image = BitmapUtil.getBitmapFromUrl(imageUrl);
if (image != null) {
// todo image.length <= 10485760
if (req.message.mediaObject instanceof WXImageObject) {
req.message.mediaObject = new WXImageObject(image);
}
req.message.thumbData = ShareUtil.bmpToByteArray(BitmapUtil.scaleCenterCrop(image, THUMB_SIZE, THUMB_SIZE));
}
// 就算图片没有了 尽量能发出分享
mIWXAPI.sendReq(req);
} catch (Throwable throwable) {
}
}
}).start();
}
示例4: shareAsEmoji
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
/**
* 分享表情
* @param context
* @param title
* @param description
* @param thumbPngPath
* @param gifPath
* @param toCicle 是否分享到朋友圈,注意有些版本的微信不支持分享到朋友圈
*/
public static final void shareAsEmoji(Context context, String title, String description, String thumbPngPath, String gifPath, boolean toCicle) {
L.d(WeChat.class, "shareAsEmoji-----");
if (!checkOperationSupport(context, toCicle)) return;
WXEmojiObject emoji = new WXEmojiObject();
emoji.emojiPath = gifPath;
WXMediaMessage msg = new WXMediaMessage(emoji);
msg.title = title;
msg.description = description;
msg.thumbData = BitmapUtils.compressToSize(BitmapUtils.readImage(thumbPngPath, THUMB_SIZE, THUMB_SIZE), THUMB_DATA_SIZE, true); //FileUtils.readBytesFromFile(thumbPngPath, 0, -1);
L.d(WeChat.class, "shareAsEmoji-----msg.thumbData:" + (msg.thumbData == null ? null : "length:" + msg.thumbData.length));
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("emoji");
req.message = msg;
req.scene = toCicle ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
getWxApi().sendReq(req);
}
示例5: share
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void share() {
SendMessageToWX.Req req = new SendMessageToWX.Req();
WXMediaMessage msg = new WXMediaMessage();
msg.setThumbImage(shareContent.getThumb());
msg.title = shareContent.getTitle();
msg.description = shareContent.getDescription();
switch (shareContent.getType()) {
case Content.Type.TEXT:
msg.mediaObject = new WXTextObject(shareContent.getText());
req.transaction = buildTransaction("text");
break;
case Content.Type.IMAGE:
msg.mediaObject = new WXImageObject(shareContent.getImage());
req.transaction = buildTransaction("img");
break;
case Content.Type.LINK:
msg.mediaObject = new WXWebpageObject(shareContent.getLink());
req.transaction = buildTransaction("webpage");
break;
}
req.message = msg;
req.scene = shareContent.isTimeline() ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
wxapi.sendReq(req);
}
示例6: shareWebPage
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
public void shareWebPage(MsgImageText mt) {
boolean isTimelineCb = false;
if (mt.pType == PType.PLATFORM_WX_friends) {
isTimelineCb = true;
}
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = mt.targetUrl+"?from=weixin";
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = mt.title;
msg.description = mt.summary;
if (mt.image != null) {
msg.thumbData = Util.bmpToByteArray(mt.image, true);
} else if (mt.imageUrl != null) {
msg.thumbData = Util.readFromFile(mt.imageUrl, 0, (int) new File(mt.imageUrl).length());
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = isTimelineCb ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
api.sendReq(req);
}
示例7: shareWebPage
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
public void shareWebPage(MsgImageText mt) {
if(mt==null)return;
boolean isTimelineCb = false;
if (mt.pType == PType.PLATFORM_WX_friends) {
isTimelineCb = true;
}
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = mt.targetUrl;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = mt.title;
msg.description = mt.summary;
if (mt.image != null) {
msg.thumbData = Util.bmpToByteArray(mt.image, true);
} else if (mt.imageUrl != null) {
msg.thumbData = Util.readFromFile(mt.imageUrl, 0, (int) new File(mt.imageUrl).length());
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = isTimelineCb ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
api.sendReq(req);
}
示例8: share
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
public boolean share(String content) {
if(!register()) {
return false;
}
WXTextObject obj = new WXTextObject();
obj.text = content;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = obj;
msg.description = content;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = String.valueOf(System.currentTimeMillis());
req.scene = SendMessageToWX.Req.WXSceneTimeline;
req.message = msg;
return mApi.sendReq(req);
}
示例9: sendMessage
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
/**
* ����Ϣ������Ȧ
*
* @param title ����
* @param description ����
* @param redirectUrl �����ת��·��
* @param bitmap ͼƬ
* @return
*/
public boolean sendMessage(Context context, String title, String description, String addressUrl){
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.back_nor);
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = addressUrl;
WXMediaMessage msg = new WXMediaMessage(webpage);
if(isShareAll){ //���������Ȧ
msg.title = description;
}else{ //�����ָ������
msg.title = title;
}
msg.description = description;
msg.thumbData = bmpToByteArray(bitmap, true);
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = isShareAll ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
// ����api�ӿڷ�����ݵ���
return api.sendReq(req);
}
示例10: sharePicture
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void sharePicture(int shareType, ShareContent shareContent) {
WXImageObject imgObj = new WXImageObject();
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = ShareUtil.buildTransaction("imgshareappdata");
req.message = msg;
req.scene = shareType;
sendShare(shareContent.getImageUrl(), req);
}
示例11: shareWebPage
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void shareWebPage(final int shareType, final ShareContent shareContent) {
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = shareContent.getURL();
final WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = shareContent.getTitle();
msg.description = shareContent.getContent();
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = ShareUtil.buildTransaction("webpage");
req.message = msg;
req.scene = shareType;
sendShare(shareContent.getImageUrl(), req);
}
示例12: shareToWechat
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void shareToWechat(boolean timeline) {
if (isPkgInstalled("com.tencent.mm")) {
// 初始化一个WXTextObject对象
Bitmap bmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_launcher);
//WXImageObject imgObj = new WXImageObject(bmp);
WXWebpageObject webObj = new WXWebpageObject();
webObj.webpageUrl = shareLink;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = webObj;
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 150, 150, true);
bmp.recycle();
msg.thumbData = Util.bmpToByteArray(thumbBmp, true); // 设置缩略图
msg.description = mContext.getResources().getString(R.string.shareDescription);
msg.title = shareText;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = timeline ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
// 调用api接口发送数据到微信
wAPI.sendReq(req);
} else {
new CommonDialog(getActivity(), "温馨提示", "未检测到“微信”应用", "确定").show();
}
}
示例13: shareToWechat
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void shareToWechat(boolean isWechatMoments,boolean isWechat, boolean isWechatFavorite, String imagePath, String comment) {
IWXAPI api = WXAPIFactory.createWXAPI(MyApp.getInstance(), MyApp.WEIXIN_KEY);
// 将该app注册到微信
api.registerApp( MyApp.WEIXIN_KEY);
WXImageObject imgObj = new WXImageObject();
imgObj.setImagePath(imagePath);
WXMediaMessage msg = new WXMediaMessage();
msg.description = comment;
msg.mediaObject = imgObj;
Bitmap bmp = BitmapFactory.decodeFile(imagePath);
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 100, 100, true);
bmp.recycle();
msg.thumbData = bmpToByteArray(thumbBmp, true);
int imageSize = msg.thumbData.length / 1024;
if (imageSize > 32) {
Toast.makeText(MyApp.getInstance(), "您分享的图片过大", Toast.LENGTH_SHORT)
.show();
return;
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("img");
req.message = msg;
req.scene = isWechat? SendMessageToWX.Req.WXSceneSession:SendMessageToWX.Req.WXSceneTimeline;
api.sendReq(req);
finish();
}
示例14: send
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
private void send(Context context, WeChatSKShareContent shareContent, boolean isToFriend, WXMediaMessage.IMediaObject mediaObject, String type) {
WXMediaMessage mediaMessage = new WXMediaMessage(mediaObject);
mediaMessage.title = shareContent.title;
mediaMessage.description = shareContent.content;
mediaMessage.thumbData = getCompressThumbImageData(shareContent, context);
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction(type);
req.message = mediaMessage;
req.scene = isToFriend ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
wxApi.sendReq(req);
}
示例15: onCreate
import com.tencent.mm.sdk.openapi.SendMessageToWX; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
api = WXAPIFactory.createWXAPI(this, WXEntryActivity.APP_ID, false);
api.registerApp(WXEntryActivity.APP_ID);
setContentView(R.layout.send_activity);
ILoginService login = (ILoginService) getSystemService("login_service");
if (login != null) {
LoginVO vo = login.login("admin", "123456");
Toast.makeText(this, vo.getUsername() + ":" + vo.getPassword(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "ILoginService == null", Toast.LENGTH_SHORT).show();
}
findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WXTextObject textObj = new WXTextObject();
textObj.text = "呵呵更健康";
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = textObj;
msg.title = "Will be ignored";
msg.description = "呵呵更健康";
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = "呵呵更健康" + String.valueOf(System.currentTimeMillis());
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneSession;//发送给某人
api.sendReq(req);
}
});
}