WXEntryActivity.java
4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.cnlive.strike.wxapi;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.cnlive.libs.base.util.AlertUtil;
import com.cnlive.share.arouter.ARouterUtil;
import com.cnlive.share.data.ShareIntegralTypeInfo;
import com.cnlive.share.util.DateTimeUtil;
import com.cnlive.strike.user.auth.UserService;
import com.google.gson.Gson;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.cnlive.share.BuildConfig;
/**
* 作者: 吴奎庆
* <p>
* 时间: 2018/8/23
* <p>
* 简介:
*/
public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
private IWXAPI api;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
api = WXAPIFactory.createWXAPI(this, BuildConfig.WECHAT_SHARE);
api.handleIntent(getIntent(), this);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
api.handleIntent(intent, this);
}
@Override
public void onReq(BaseReq baseReq) {
}
@Override
public void onResp(BaseResp baseResp) {
String result = "";
Log.e("分享", baseResp.errCode + "");
switch (baseResp.errCode) {
case BaseResp.ErrCode.ERR_OK:
result = "分享完成";
break;
case BaseResp.ErrCode.ERR_USER_CANCEL:
result = "分享取消";
break;
case BaseResp.ErrCode.ERR_AUTH_DENIED:
result = "分享失败";
break;
default:
result = "分享失败";
break;
}
AlertUtil.showDeftToast(this, result);
processShareType(baseResp);
this.finish();
}
/**
* 更具不同的分享类型处理不同的 分享逻辑
*
* @param baseResp
*/
private void processShareType(BaseResp baseResp) {
String shareType = baseResp.transaction;
if (TextUtils.isEmpty(shareType)) return;
try {
Gson gson = new Gson();
ShareIntegralTypeInfo integralTypeInfo = gson.fromJson(shareType, ShareIntegralTypeInfo.class);
if ("witnessVideo".equals(integralTypeInfo.getShareType())) {
SharedPreferences preferences = this.getSharedPreferences("sharevideo", MODE_PRIVATE);
boolean status = preferences.getBoolean(UserService.getUid(this), false);
String newTime = DateTimeUtil.getCurrentTime();
String oldtime = preferences.getString(UserService.getUid(this) + "time", "2019-04-10");
boolean sameDay = DateTimeUtil.isSameDay(newTime, oldtime);
if (!status) {
ARouterUtil.addIntegrationPic(this,"share_video", integralTypeInfo.getContentId(), "sharevideo");
}
if (status && !sameDay){
ARouterUtil.addIntegrationPic(this,"share_video", integralTypeInfo.getContentId(), "sharevideo");
}
} else if (integralTypeInfo.getShareType() != null) {
SharedPreferences preferences = this.getSharedPreferences("sharearticle", MODE_PRIVATE);
boolean status = preferences.getBoolean(UserService.getUid(this), false);
String newTime = DateTimeUtil.getCurrentTime();
String oldtime = preferences.getString(UserService.getUid(this) + "time", "2019-04-10");
boolean sameDay = DateTimeUtil.isSameDay(newTime, oldtime);
if (!status) {
ARouterUtil.addIntegrationPic(this,"share_article", integralTypeInfo.getContentId(), "sharearticle");
}
if (status && !sameDay){
ARouterUtil.addIntegrationPic(this,"share_article", integralTypeInfo.getContentId(), "sharearticle");
}
}
} catch (Exception e) {
return;
}
}
}