/**
   * @param type 0:分享到微信好友,1:分享到微信朋友圈
   * @param url 分享链接
   */
  private void senWechatReq(final int type, String url, String title, String des, String img) {
    WXWebpageObject webpage = new WXWebpageObject();
    webpage.webpageUrl = url;
    final WXMediaMessage wechatmsg = new WXMediaMessage(webpage);
    wechatmsg.title = title;
    wechatmsg.description = des;
    Bitmap thumb = BitmapFactory.decodeResource(getResources(), R.drawable.worklife_ic_launcher);
    wechatmsg.thumbData = bmpToByteArray(thumb, true);
    // ImageLoader.getInstance().loadImage(img,new
    // SimpleImageLoadingListener(){
    // @Override public void onLoadingComplete(String imageUri, View view,
    // Bitmap loadedImage) {
    // super.onLoadingComplete(imageUri, view, loadedImage);
    // if (loadedImage != null) {
    // wechatmsg.thumbData = bmpToByteArray(loadedImage, true);
    // SendMessageToWX.Req req = new SendMessageToWX.Req();
    // req.transaction = buildTransaction("webpage");
    // req.message = wechatmsg;
    // req.scene = type==0 ? SendMessageToWX.Req.WXSceneTimeline :
    // SendMessageToWX.Req.WXSceneSession;
    // api.sendReq(req);
    // }
    // }
    // });

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("webpage");
    req.message = wechatmsg;
    req.scene =
        type == 0 ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
    api.sendReq(req);
  }
  @Override
  public void onClick(View arg0) {
    switch (arg0.getId()) {
      case R.id.btn_back:
        finish();
        break;
      case R.id.btn_newsdalycomment_add:
        addComment();
        break;
      case R.id.btn_newsdayly_share:
        // 启动微信
        // Toast.makeText(this, String.valueOf(api.openWXApp()),
        // Toast.LENGTH_LONG)
        // .show();
        // 发送文本到朋友圈
        //
        // String text = "application test";
        // WXTextObject textObj = new WXTextObject();
        // textObj.text = text;
        //
        // WXMediaMessage msg = new WXMediaMessage(textObj);
        // msg.mediaObject = textObj;
        // msg.description = text;
        //
        // SendMessageToWX.Req req = new SendMessageToWX.Req();
        // req.transaction = String.valueOf(System.currentTimeMillis());
        // req.message = msg;
        // req.scene = SendMessageToWX.Req.WXSceneTimeline;
        //
        // api.sendReq(req);

        // Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
        // R.drawable.ic_seehdu);
        // WXImageObject imgobj = new WXImageObject(bitmap);
        // WXMediaMessage msg = new WXMediaMessage();
        // msg.mediaObject = imgobj;
        // Bitmap thumbitmap = Bitmap.createScaledBitmap(bitmap, 120, 150,
        // true);
        // bitmap.recycle();
        // msg.thumbData = bmpToArray(thumbitmap, true);
        // SendMessageToWX.Req req = new SendMessageToWX.Req();
        // req.transaction = String.valueOf(System.currentTimeMillis());
        // req.message = msg;
        // req.scene = SendMessageToWX.Req.WXSceneTimeline;
        // api.sendReq(req);
        //
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = surl;
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = stitle;
        msg.description = "application test";
        msg.mediaObject = webpage;
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_seehdu);
        Bitmap thumbitmap = Bitmap.createScaledBitmap(bitmap, 120, 150, true);
        bitmap.recycle();
        msg.thumbData = bmpToArray(thumbitmap, true);
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = msg;
        req.scene = SendMessageToWX.Req.WXSceneTimeline;

        api.sendReq(req);
    }
  }
  private void share(JSONArray params, final CallbackContext callbackContext)
      throws JSONException, MalformedURLException, IOException {
    // 目前只支持 WXWebpageObject 分享
    // params[0] -- 分享的目标场景(0会话,1朋友圈,2微信收藏)
    // params[1] -- 分享内容的目标 url
    // params[2] -- 标题
    // params[3] -- 描述
    // params[4] -- 图片url
    // 返回值:0-成功;1-微信未安装;2-发送失败
    // final IWXAPI api = ShareWechatPlugin.api;
    if (!api.isWXAppInstalled()) {
      callbackContext.error(ERR_WECHAT_NOT_INSTALLED);
      return;
    }
    if (params == null) {
      callbackContext.error(ERR_INVALID_OPTIONS);
      return;
    }

    int targetScene = params.getInt(0);
    String webUrl = params.getString(1);
    String title = params.getString(2);
    String description = params.getString(3);
    String imgUrl = params.getString(4);

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

    try {
      Bitmap bmp = BitmapFactory.decodeStream(new URL(imgUrl).openStream());
      Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
      bmp.recycle();
      msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
    } catch (Exception e) {
      callbackContext.error(e.getMessage());
      return;
    }

    final SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("webpage");
    req.message = msg;
    switch (targetScene) {
      case 0:
        req.scene = SendMessageToWX.Req.WXSceneSession;
        break;
      case 1:
        req.scene = SendMessageToWX.Req.WXSceneTimeline;
        break;
      case 2:
        req.scene = SendMessageToWX.Req.WXSceneFavorite;
        break;
      default:
        req.scene = SendMessageToWX.Req.WXSceneTimeline;
    }

    // run in background
    //        cordova.getThreadPool().execute(new Runnable() {
    //            @Override
    //            public void run() {
    //                if (api.sendReq(req)) {
    //                    Log.i(TAG, "wechat message sent successfully.");
    //                    //send success
    //                    callbackContext.success(NO_RESULT);
    //                } else {
    //                    Log.i(TAG, "wechat message sent failed.");
    //                    // send error
    //                    callbackContext.error(ERR_SENT_FAILED);
    //                }
    //            }
    //        });

    try {
      boolean success = api.sendReq(req);
      if (!success) {
        callbackContext.error(ERR_SENT_FAILED);
        return;
      } else {
        callbackContext.success(SUCCESS);
      }
    } catch (Exception e) {
      callbackContext.error(e.getMessage());
      return;
    }

    currentCallbackContext = callbackContext;
  }