Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-android
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a52972bf
authored
Nov 05, 2021
by
amateur
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
249e1cde
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
13 deletions
app/src/main/java/com/polysoft/nafmii/utils/BitmapUtils.java
app/src/main/java/com/polysoft/nafmii/wechat/WechatApi.java
app/src/main/java/com/polysoft/nafmii/utils/BitmapUtils.java
View file @
a52972b
...
...
@@ -517,4 +517,18 @@ public class BitmapUtils {
}
return
degree
;
}
public
static
byte
[]
bitmapToByte
(
Bitmap
bitmap
)
{
ByteArrayOutputStream
baos
=
null
;
try
{
baos
=
new
ByteArrayOutputStream
();
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
baos
);
return
baos
.
toByteArray
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
IOUtils
.
close
(
baos
);
}
return
new
byte
[]{};
}
}
app/src/main/java/com/polysoft/nafmii/wechat/WechatApi.java
View file @
a52972b
...
...
@@ -12,10 +12,13 @@ import com.alibaba.fastjson.JSON;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.request.target.SimpleTarget
;
import
com.bumptech.glide.request.transition.Transition
;
import
com.polysoft.nafmii.utils.BitmapUtils
;
import
com.tencent.mm.opensdk.modelbase.BaseReq
;
import
com.tencent.mm.opensdk.modelmsg.SendAuth
;
import
com.tencent.mm.opensdk.modelmsg.SendMessageToWX
;
import
com.tencent.mm.opensdk.modelmsg.WXImageObject
;
import
com.tencent.mm.opensdk.modelmsg.WXMediaMessage
;
import
com.tencent.mm.opensdk.modelmsg.WXTextObject
;
import
com.tencent.mm.opensdk.modelmsg.WXWebpageObject
;
import
com.tencent.mm.opensdk.modelpay.PayReq
;
import
com.tencent.mm.opensdk.openapi.IWXAPI
;
...
...
@@ -72,30 +75,39 @@ public class WechatApi {
}
public
void
share
(
Context
ctx
,
final
ShareBean
bean
)
{
if
(
"2"
.
equals
(
bean
.
getScene
()))
{
}
String
webImg
=
bean
.
getWebImg
();
String
shareType
=
bean
.
getShareType
();
if
(
"0"
.
equals
(
shareType
))
{
// 分享文字
this
.
shareText
(
bean
);
}
else
if
(
"1"
.
equals
(
shareType
))
{
// 分享图片
this
.
shareImage
(
bean
);
this
.
loadImageUrl
(
ctx
,
webImg
,
(
bitmap
)
->
shareImage
(
bean
,
bitmap
)
);
}
else
if
(
"3"
.
equals
(
shareType
))
{
// 分享url地址
this
.
loadImageUrl
(
ctx
,
webImg
,
new
Callback
<
Bitmap
>()
{
@Override
public
void
onBack
(
Bitmap
data
)
{
shareWebPage
(
bean
,
data
);
}
});
this
.
loadImageUrl
(
ctx
,
webImg
,
(
bitmap
)
->
shareWebPage
(
bean
,
bitmap
));
}
}
private
void
shareText
(
ShareBean
bean
)
{
WXTextObject
textObj
=
new
WXTextObject
();
textObj
.
text
=
bean
.
getContent
();
WXMediaMessage
msg
=
new
WXMediaMessage
();
msg
.
mediaObject
=
textObj
;
msg
.
description
=
bean
.
getContent
();
this
.
shareAction
(
msg
,
bean
,
"text"
);
}
private
void
shareImage
(
ShareBean
bean
)
{
private
void
shareImage
(
ShareBean
bean
,
Bitmap
bmp
)
{
//初始化 WXImageObject 和 WXMediaMessage 对象
WXImageObject
imgObj
=
new
WXImageObject
(
bmp
);
WXMediaMessage
msg
=
new
WXMediaMessage
();
msg
.
mediaObject
=
imgObj
;
Bitmap
thumbBmp
=
Bitmap
.
createScaledBitmap
(
bmp
,
120
,
120
,
true
);
bmp
.
recycle
();
msg
.
thumbData
=
BitmapUtils
.
bitmapToByte
(
thumbBmp
);
this
.
shareAction
(
msg
,
bean
,
"img"
);
}
...
...
@@ -111,9 +123,14 @@ public class WechatApi {
msg
.
setThumbImage
(
bitmap
);
bitmap
.
recycle
();
this
.
shareAction
(
msg
,
bean
,
"webpage"
);
}
private
void
shareAction
(
WXMediaMessage
msg
,
ShareBean
bean
,
String
transaction
)
{
SendMessageToWX
.
Req
req
=
new
SendMessageToWX
.
Req
();
// transaction用于唯一标识一个请求(可自定义)
req
.
transaction
=
"webpage"
;
req
.
transaction
=
transaction
;
// 上文的WXMediaMessage对象
req
.
message
=
msg
;
req
.
scene
=
this
.
getShareScene
(
bean
);
...
...
@@ -121,7 +138,6 @@ public class WechatApi {
this
.
sendRequest
(
req
);
}
private
int
getShareScene
(
ShareBean
bean
)
{
String
scene
=
bean
.
getScene
();
if
(
"0"
.
equals
(
scene
))
{
// 朋友圈
...
...
@@ -145,6 +161,7 @@ public class WechatApi {
}
};
if
(
TextUtils
.
isEmpty
(
url
))
{
Glide
.
with
(
ctx
).
asBitmap
().
load
(
R
.
mipmap
.
app_logo
).
override
(
120
,
120
).
into
(
target
);
}
else
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment