本文整理汇总了Java中com.tencent.mm.opensdk.modelmsg.SendMessageToWX类的典型用法代码示例。如果您正苦于以下问题:Java SendMessageToWX类的具体用法?Java SendMessageToWX怎么用?Java SendMessageToWX使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SendMessageToWX类属于com.tencent.mm.opensdk.modelmsg包,在下文中一共展示了SendMessageToWX类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResp
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
@Override
public void onResp(BaseResp resp) {
Log.e(TAG, "transaction = " + resp.transaction + ", type = " + resp.getType() + ", errCode = " + resp.errCode + ", err = " + resp.errStr);
if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
switch (resp.getType()) {
case ConstantsAPI.COMMAND_SENDAUTH:
onResultOk((SendAuth.Resp) resp);
break;
case ConstantsAPI.COMMAND_PAY_BY_WX:
onResultOk((PayResp) resp);
break;
case ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX:
onResultOk((SendMessageToWX.Resp) resp);
break;
}
} else if (resp.errCode == BaseResp.ErrCode.ERR_USER_CANCEL) {
mCallback.onFailed(mActivity, ResultCode.RESULT_CANCELLED, toMessage(resp));
} else {
mCallback.onFailed(mActivity, ResultCode.RESULT_FAILED, toMessage(resp));
}
mCallback.onCompleted(mActivity);
}
示例2: 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;
}
示例3: share
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
@Override
public void share(final int shareId) {
mapObject.captureMap(new IMapCaptureFinished() {
@Override
public void onMapCaptureFinished(Bitmap bitmap, int status) {
WXImageObject imageObject = new WXImageObject(bitmap);
WXMediaMessage mediaMessage = new WXMediaMessage();
mediaMessage.mediaObject = imageObject;
Bitmap thumb = Bitmap.createScaledBitmap(bitmap,50,50,true);
bitmap.recycle();
mediaMessage.thumbData = ShareUtils.bmpToByteArray(thumb,true);
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = ShareUtils.buildTransaction("img");
req.message = mediaMessage;
if(shareId == R.id.btn_share_to_friend){
req.scene = SendMessageToWX.Req.WXSceneSession;
}
else{
req.scene = SendMessageToWX.Req.WXSceneTimeline;
}
CFLog.e("Share","send = "+ mWxApi.sendReq(req));
}
});
}
示例4: clickShare
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
@OnClick(R.id.tv_me_share) void clickShare() {
android.app.AlertDialog.Builder builder=new android.app.AlertDialog.Builder(getActivity());
builder.setIcon(R.mipmap.app_icon);
builder.setTitle("爱分享的人运气总不会差");
builder.setItems(R.array.shareList, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
int scene = SendMessageToWX.Req.WXSceneSession;
if(which == 1) {
scene = SendMessageToWX.Req.WXSceneTimeline;
}else if(which == 2){
scene = SendMessageToWX.Req.WXSceneFavorite;
}
ShareUtils.install(getActivity());
ShareUtils.shareWeb(getActivity(),getResources().getString(R.string.app_name)+",你的掌上校园伴侣","广财专用APP,学生开发,课表饭卡校园网,一样不少",AppConfig.WXSHARE_URL, scene);
}
});
builder.create().show();
}
示例5: 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);
}
示例6: WXHandler
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
public WXHandler() {
this.mEventHandler = new IWXAPIEventHandler() {
public void onResp(BaseResp resp) {
if(!mLastTransaction.equals(resp.transaction)) {
return;
}
int type = resp.getType();
switch(type) {
case ConstantsAPI.COMMAND_SENDAUTH: //授权返回
WXHandler.this.onAuthCallback((SendAuth.Resp)resp);
break;
case ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX: //分享返回
WXHandler.this.onShareCallback((SendMessageToWX.Resp)resp);
break;
}
}
public void onReq(BaseReq req) {
}
};
}
示例7: onShareCallback
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
protected void onShareCallback(com.tencent.mm.opensdk.modelmsg.SendMessageToWX.Resp resp) {
switch (resp.errCode) {
case BaseResp.ErrCode.ERR_OK: //分享成功
if(this.mShareListener != null) {
this.mShareListener.onComplete(this.mConfig.getName());
}
break;
case BaseResp.ErrCode.ERR_USER_CANCEL: //分享取消
if(this.mShareListener != null) {
this.mShareListener.onCancel(this.mConfig.getName());
}
break;
default: //分享失败
CharSequence err = TextUtils.concat(new CharSequence[]{"weixin share error (", String.valueOf(resp.errCode), "):", resp.errStr});
if(mShareListener != null) {
mShareListener.onError(this.mConfig.getName(), err.toString());
}
break;
}
}
示例8: 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);
}
示例9: shareImage
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
@Override
protected void shareImage(final ShareParamImage params) throws ShareException {
mImageHelper.downloadImageIfNeed(params, new Runnable() {
@Override
public void run() {
WXImageObject imgObj = buildWXImageObject(params.getImage());
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
msg.thumbData = mImageHelper.buildThumbData(params.getImage());
final SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("imgshareappdata");
req.message = msg;
req.scene = getShareType();
Log.d(TAG, "start share image");
shareOnMainThread(req);
}
});
}
示例10: buildTransaction
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
/**
* 根据scene创建一个transaction字符串,从微信返回的时候会携带这个字符串
* @param scene
* @return
*/
private static String buildTransaction(@Scene int scene) {
String tag = null;
if (scene == SendMessageToWX.Req.WXSceneSession){
tag = TAG_SESSION;
}else if (scene == SendMessageToWX.Req.WXSceneTimeline){
tag = TAG_TIMELINE;
}else if (scene == SendMessageToWX.Req.WXSceneFavorite){
tag = TAG_FAVORITE;
}else {
// can't reach
tag = TAG_UNKNOWN;
}
return tag + System.currentTimeMillis();
}
示例11: getShareToWhere
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
private int getShareToWhere(int shareTarget) {
int where = SendMessageToWX.Req.WXSceneSession;
switch (shareTarget) {
case Target.SHARE_WX_FRIENDS:
where = SendMessageToWX.Req.WXSceneSession;
break;
case Target.SHARE_WX_ZONE:
where = SendMessageToWX.Req.WXSceneTimeline;
break;
case Target.SHARE_WX_FAVORITE:
where = SendMessageToWX.Req.WXSceneFavorite;
break;
}
return where;
}
示例12: 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失败,可能是参数错误"));
}
}
示例13: 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);
}
示例14: 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);
}
示例15: 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()方法");
}
}