更新优化
This commit is contained in:
@@ -298,6 +298,90 @@ public class HttpMD5SendInfoUtil {
|
||||
|
||||
}
|
||||
|
||||
public static void sendHttp(final String postUrl, Map<String, String> params, final OnCallBackFromNet callBack) {
|
||||
|
||||
HttpHelper.loadData(HttpMethod.GET, Url.getTimestamp,null, new RequestCallBack<String>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ResponseInfo<String> info) {
|
||||
Map<String, String> param=new HashMap<>();
|
||||
if(params != null){
|
||||
param.putAll(params);
|
||||
}
|
||||
|
||||
String uuid = SharePrefUtil.getString(getContext(), Constant.uuid, "");
|
||||
if(StringUtil.isEmpty(uuid))
|
||||
{
|
||||
uuid= LogoutHelper.addUMTokenuuid;
|
||||
}
|
||||
param.put("user_uuid", uuid);
|
||||
TimestampBean bean = GsonTools.fromGsonToBean(info.result, TimestampBean.class);
|
||||
param.put("timestamp", bean.getTimestamp());
|
||||
param.put("client_type", "A");
|
||||
param.put("version", UpdateVersionUtils.getVersionName());
|
||||
new Thread() {
|
||||
public void run() {
|
||||
String encoding = "UTF-8";
|
||||
Gson gson = new Gson();
|
||||
String params = gson.toJson(param);
|
||||
byte[] data;
|
||||
try {
|
||||
String sign = SignUtil.getSign(param);
|
||||
LogUtil.i("params = "+params.toString());
|
||||
data = params.getBytes(encoding);
|
||||
URL url = new URL(postUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
conn.setRequestProperty("Content-Type","application/json");
|
||||
conn.setRequestProperty("sign",sign);
|
||||
conn.setRequestProperty("Content-Length",String.valueOf(data.length));
|
||||
conn.setConnectTimeout(5 * 1000);
|
||||
OutputStream outStream = conn.getOutputStream();
|
||||
outStream.write(data);
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
int ssss=conn.getResponseCode() ;
|
||||
if (ssss == 200) {
|
||||
InputStream inStream = conn.getInputStream();
|
||||
String result = new String(StreamTool.readInputStream(inStream), "UTF-8");
|
||||
String string = new String(result);
|
||||
LogUtil.i("result = "+result);
|
||||
JSONObject jsonObject = new JSONObject(string);
|
||||
String optString = jsonObject.optString("code");
|
||||
String message = jsonObject.optString("message");
|
||||
// Log.d("okhttp","result = "+result);
|
||||
Log.d("okhttp","getRealyWorldToken "+result);
|
||||
if ("200".equals(optString)) {
|
||||
LogUtil.e("请求成功");
|
||||
callBack.onCallbackFromThread(string);
|
||||
}
|
||||
else{
|
||||
callBack.onCallbackFromThread(string);
|
||||
}
|
||||
}else {
|
||||
LogUtil.e("Code = "+ssss);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.e("提交失败,请重试 = "+e.getMessage());
|
||||
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException arg0, String arg1) {
|
||||
// ToastUtil.showToast("请求失败,请重试");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void sendJsonPostParamTokenMD5(Context context,final OnCallBackFromNet callBack){
|
||||
|
||||
|
||||
@@ -64,7 +64,8 @@ import io.dcloud.feature.unimp.config.UniMPOpenConfiguration;
|
||||
public class MyUserIconUtil {
|
||||
public static void myIntent(Context context,String name){
|
||||
if ("肝胆新闻".equals(name)||"肝胆时讯".equals(name)){
|
||||
context.startActivity(new Intent(context, GandanConsultActivity.class));
|
||||
// context.startActivity(new Intent(context, GandanConsultActivity.class));
|
||||
UniappUtil.showUniMp(context, "/pages_app/newsList/newsList", null);
|
||||
}else if ("名医名科".equals(name)){
|
||||
context.startActivity(new Intent(context, GanDanHospitalActivity.class));
|
||||
}else if ("药品助手".equals(name)){
|
||||
@@ -74,7 +75,7 @@ public class MyUserIconUtil {
|
||||
context.startActivity(intentwf);
|
||||
}else if ("肝胆课件".equals(name)){
|
||||
// context.startActivity(new Intent(context, CoursewareActivity.class));
|
||||
showUniMp(context, "/pages_app/ppt/ppt", null);
|
||||
UniappUtil.showUniMp(context, "/pages_app/ppt/ppt", null);
|
||||
}else if ("精品课程".equals(name)){
|
||||
context.startActivity(new Intent(context, QualityCourseActivity.class));
|
||||
}else if ("肝病学院".equals(name)){
|
||||
@@ -93,15 +94,18 @@ public class MyUserIconUtil {
|
||||
intent1.setType("download");
|
||||
context.startActivity(intent1);
|
||||
}else if ("我的福利".equals(name)){
|
||||
Intent intent1 = new Intent(context, MyWelfAreActivity.class);
|
||||
context.startActivity(intent1);
|
||||
// Intent intent1 = new Intent(context, MyWelfAreActivity.class);
|
||||
// context.startActivity(intent1);
|
||||
|
||||
UniappUtil.showUniMp(context, "/pages_app/myWelfare/myWelfare", null);
|
||||
}else if ("精品课".equals(name)){
|
||||
Intent intent1 = new Intent(context, CourseActivity.class);
|
||||
context.startActivity(intent1);
|
||||
}
|
||||
else if("积分商城".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, PointsMallActivity.class));
|
||||
// context.startActivity(new Intent(context, PointsMallActivity.class));
|
||||
UniappUtil.showUniMp(context, "/pages_goods/pointMall/pointMall", null);
|
||||
// context.startActivity(new Intent(context, ResearchActivity.class));
|
||||
}
|
||||
else if("我的患者".equals(name))
|
||||
@@ -112,7 +116,7 @@ public class MyUserIconUtil {
|
||||
{
|
||||
// context.startActivity(new Intent(context, VideoActivity.class));
|
||||
// 调用公共方法打开uniapp mp
|
||||
showUniMp(context, "/pages_app/video/video", null);
|
||||
UniappUtil.showUniMp(context, "/pages_app/video/video", null);
|
||||
}
|
||||
else if("公益咨询".equals(name))
|
||||
{
|
||||
@@ -122,7 +126,7 @@ public class MyUserIconUtil {
|
||||
{
|
||||
// context.startActivity(new Intent(context, MyLibraryActivity.class));
|
||||
// 调用公共方法打开uniapp mp
|
||||
showUniMp(context, "/pages_app/zhinan/zhinan", null);
|
||||
UniappUtil.showUniMp(context, "/pages_app/zhinan/zhinan", null);
|
||||
}
|
||||
else if ("专题e站".equals(name)){
|
||||
Intent intent1 = new Intent(context, NewsDetailActivity.class);
|
||||
@@ -143,23 +147,29 @@ public class MyUserIconUtil {
|
||||
else
|
||||
{
|
||||
context.startActivity(new Intent(context, NormNewPatientActivity.class));
|
||||
// UniappUtil.showUniMp(context, "/pages_app/myPatient/myPatient", null);
|
||||
}
|
||||
}
|
||||
else if("患者分组".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, GroupingActivity.class));
|
||||
|
||||
// UniappUtil.showUniMp(context, "/pages_app/patientGroup/patientGroup", null);
|
||||
}
|
||||
else if("群发消息".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, SendGroupMsgListActivity.class));
|
||||
// UniappUtil.showUniMp(context, "/pages_chat/groupMessage/groupMessage", null);
|
||||
}
|
||||
else if("随访二维码".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, MyQrCodeActivity.class));
|
||||
// context.startActivity(new Intent(context, MyQrCodeActivity.class));
|
||||
UniappUtil.showUniMp(context, "/pages_app/myCode/myCode", null);
|
||||
}
|
||||
else if("出诊计划".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, OutofPatientNoticeActivity.class));
|
||||
// context.startActivity(new Intent(context, OutofPatientNoticeActivity.class));
|
||||
UniappUtil.showUniMp(context, "/pages_chat/outPatient/outPatient", null);
|
||||
}
|
||||
else if("我的视频".equals(name))
|
||||
{
|
||||
@@ -180,19 +190,23 @@ public class MyUserIconUtil {
|
||||
}
|
||||
else if("我的账户".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, MyAccount2Activity.class));
|
||||
// context.startActivity(new Intent(context, MyAccount2Activity.class));
|
||||
UniappUtil.showUniMp(context, "/pages_app/myAccount/myAccount", null);
|
||||
}
|
||||
else if("我的积分".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, AccumulatePointsActivity.class));
|
||||
// context.startActivity(new Intent(context, AccumulatePointsActivity.class));
|
||||
UniappUtil.showUniMp(context, "/pages_app/myPoint/myPoint", null);
|
||||
}
|
||||
else if("我的鲜花".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, MyFlowerActivity.class));
|
||||
// context.startActivity(new Intent(context, MyFlowerActivity.class));
|
||||
UniappUtil.showUniMp(context, "/pages_app/myFlower/myFlower", null);
|
||||
}
|
||||
else if("课件明细".equals(name))
|
||||
{
|
||||
context.startActivity(new Intent(context, MyCoursewareActivity.class));
|
||||
// context.startActivity(new Intent(context, MyCoursewareActivity.class));
|
||||
UniappUtil.showUniMp(context, "/pages_app/myCourseware/myCourseware", null);
|
||||
}
|
||||
else if("课程明细".equals(name))
|
||||
{
|
||||
@@ -240,59 +254,6 @@ public class MyUserIconUtil {
|
||||
// context.startActivity(new Intent(context, PointsMallActivity.class));
|
||||
context.startActivity(new Intent(context, ResearchActivity.class));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示uniapp mp - 公共方法
|
||||
* @param context 上下文
|
||||
* @param targetPath
|
||||
*/
|
||||
public static void showUniMp(Context context, String targetPath, com.alibaba.fastjson.JSONObject pageParams) {
|
||||
try {
|
||||
String uuid = SharePrefUtil.getString(context, Constant.uuid, "");
|
||||
if(StringUtil.isEmpty(uuid)){
|
||||
return;
|
||||
}
|
||||
String access_token = SharePrefUtil.getString(context, "access_token", "");
|
||||
String QueryString = StringUtil.toQueryString(pageParams);
|
||||
JSONObject userInfo = new JSONObject();
|
||||
userInfo.put("uuid", SharePrefUtil.getString(context, Constant.uuid, ""));
|
||||
userInfo.put("realName", SharePrefUtil.getString(context, Constant.realName, ""));
|
||||
userInfo.put("mobile", SharePrefUtil.getString(context, "mobile", ""));
|
||||
userInfo.put("photo", SharePrefUtil.getString(context, Constant.photo, ""));
|
||||
|
||||
UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration();
|
||||
uniMPOpenConfiguration.splashClass = UniappSplashView.class;
|
||||
uniMPOpenConfiguration.extraData.put("darkmode", "light");
|
||||
uniMPOpenConfiguration.extraData.put("apiHost", url_path);
|
||||
uniMPOpenConfiguration.extraData.put("token", access_token);
|
||||
uniMPOpenConfiguration.extraData.put("userInfo", userInfo);
|
||||
|
||||
IUniMP uniapp_MP_cash = BaseApplication.getUniMPCaches().get(uniapp_mp_appid);
|
||||
if(uniapp_MP_cash != null && uniapp_MP_cash.isRunning()){
|
||||
uniapp_MP_cash.sendUniMPEvent("goPage", targetPath+QueryString);
|
||||
uniapp_MP_cash.showUniMP();
|
||||
}else{
|
||||
if(StringUtil.notEmpty(targetPath)){
|
||||
uniMPOpenConfiguration.extraData.put("targetPath", targetPath+QueryString);
|
||||
}
|
||||
IUniMP uniapp_MP = DCUniMPSDK.getInstance().openUniMP(mContext, uniapp_mp_appid, uniMPOpenConfiguration);
|
||||
BaseApplication.getUniMPCaches().put(uniapp_MP.getAppid(), uniapp_MP);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeUniMP(){
|
||||
IUniMP uniapp_MP = BaseApplication.getUniMPCaches().get(uniapp_mp_appid);
|
||||
if(uniapp_MP != null && uniapp_MP.isRunning()){
|
||||
uniapp_MP.closeUniMP();
|
||||
BaseApplication.getUniMPCaches().remove(uniapp_mp_appid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package cn.shangyu.gdxzExpert.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* uniapp 下载工具
|
||||
*/
|
||||
public class UniappDownloadUtil {
|
||||
|
||||
private static UniappDownloadUtil downloadUtil;
|
||||
private final OkHttpClient okHttpClient;
|
||||
private Context context;
|
||||
private String TAG = "下载页面";
|
||||
|
||||
public static UniappDownloadUtil get() {
|
||||
if (downloadUtil == null) {
|
||||
downloadUtil = new UniappDownloadUtil();
|
||||
}
|
||||
return downloadUtil;
|
||||
}
|
||||
|
||||
private UniappDownloadUtil() {
|
||||
okHttpClient = new OkHttpClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url 下载连接
|
||||
* @param saveDir 储存下载文件的SDCard目录
|
||||
* @param listener 下载监听
|
||||
*/
|
||||
public void download(Context context, final String url, final String saveDir, final String fileName, final OnDownloadListener listener) {
|
||||
this.context= context;
|
||||
// 需要token的时候可以这样做
|
||||
// SharedPreferences sp=MyApp.getAppContext().getSharedPreferences("loginInfo", MODE_PRIVATE);
|
||||
// Request request = new Request.Builder().header("token",sp.getString("token" , "")).url(url).build();
|
||||
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
|
||||
okHttpClient.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
// 下载失败
|
||||
listener.onDownloadFailed();
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
InputStream is = null;
|
||||
byte[] buf = new byte[2048];
|
||||
int len = 0;
|
||||
FileOutputStream fos = null;
|
||||
// 储存下载文件的目录
|
||||
String savePath = isExistDir(saveDir);
|
||||
Log.w(TAG,"存储下载目录:"+savePath);
|
||||
try {
|
||||
is = response.body().byteStream();
|
||||
long total = response.body().contentLength();
|
||||
File file = new File(savePath, getNameFromUrl(fileName));
|
||||
Log.w(TAG,"最终路径:"+file);
|
||||
fos = new FileOutputStream(file);
|
||||
long sum = 0;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
sum += len;
|
||||
int progress = (int) (sum * 1.0f / total * 100);
|
||||
// 下载中
|
||||
listener.onDownloading(progress);
|
||||
}
|
||||
fos.flush();
|
||||
// 下载完成
|
||||
listener.onDownloadSuccess(file);
|
||||
} catch (Exception e) {
|
||||
listener.onDownloadFailed();
|
||||
} finally {
|
||||
try {
|
||||
if (is != null)
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
try {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param saveDir
|
||||
* @return
|
||||
* @throws IOException
|
||||
* 判断下载目录是否存在
|
||||
*/
|
||||
private String isExistDir(String saveDir) throws IOException {
|
||||
// saveDir 已经是完整路径(例如:/storage/emulated/0/Android/data/cn.shangyu.gdxzExpert/cache)
|
||||
// 直接使用该路径,确保目录存在
|
||||
File downloadFile = new File(saveDir);
|
||||
if (!downloadFile.exists()) {
|
||||
boolean created = downloadFile.mkdirs();
|
||||
if (!created && !downloadFile.exists()) {
|
||||
throw new IOException("无法创建下载目录: " + saveDir);
|
||||
}
|
||||
}
|
||||
String savePath = downloadFile.getAbsolutePath();
|
||||
Log.w(TAG,"下载目录:"+savePath);
|
||||
return savePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url
|
||||
* @return
|
||||
* 传入文件名
|
||||
*/
|
||||
@NonNull
|
||||
public String getNameFromUrl(String url) {
|
||||
return url;
|
||||
}
|
||||
|
||||
public interface OnDownloadListener {
|
||||
/**
|
||||
* 下载成功
|
||||
*/
|
||||
void onDownloadSuccess(File file);
|
||||
|
||||
/**
|
||||
* @param progress
|
||||
* 下载进度
|
||||
*/
|
||||
void onDownloading(int progress);
|
||||
|
||||
/**
|
||||
* 下载失败
|
||||
*/
|
||||
void onDownloadFailed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
package cn.shangyu.gdxzExpert.utils;
|
||||
|
||||
import static com.taobao.accs.ACCSManager.mContext;
|
||||
import static cn.shangyu.gdxzExpert.utils.Constant.token;
|
||||
import static cn.shangyu.gdxzExpert.utils.Constant.uniapp_mp_appid;
|
||||
import static cn.shangyu.gdxzExpert.utils.HttpMD5SendInfoUtil.sendJsonPostParamTokenMD5;
|
||||
import static cn.shangyu.gdxzExpert.utils.UIUtils.getContext;
|
||||
import static cn.shangyu.gdxzExpert.utils.Url.url_path;
|
||||
import static cn.shangyu.gdxzExpert.utils.Url.weurl;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import cn.shangyu.gdxzExpert.activity.BindWeChatActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.CaseDetailActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.CasediscussionActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.CourseActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.EditPhoneActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.GDLiveBroadcastActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.GanDanHospitalActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.GandanConsultActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.GroupingActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyAccount2Activity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyCicleActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyCoursewareActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyDownLoadsActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyFlowerActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyLibraryActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyPatientActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyQrCodeActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.MyScientificResearchActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.NewsDetailActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.OrderListActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.OutofPatientNoticeActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.PublicConsultationActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.ResearchActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.SendGroupMsgListActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.SendMindActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.SettingVersionActivity;
|
||||
import cn.shangyu.gdxzExpert.activity.TestingActivity;
|
||||
import cn.shangyu.gdxzExpert.application.BaseApplication;
|
||||
import cn.shangyu.gdxzExpert.bean.SimpleBean;
|
||||
import cn.shangyu.gdxzExpert.bean.UniappMpCheckWgt;
|
||||
import cn.shangyu.gdxzExpert.big.activity.BiggNewPatientActivity;
|
||||
import cn.shangyu.gdxzExpert.big.activity.NormNewPatientActivity;
|
||||
import cn.shangyu.gdxzExpert.http.OnCallBackFromNet;
|
||||
import cn.shangyu.gdxzExpert.polyvplayer.MyDownLoadVideoActivity;
|
||||
import cn.shangyu.gdxzExpert.polyvplayer.QualityCourseActivity;
|
||||
import cn.shangyu.gdxzExpert.splash.UniappSplashView;
|
||||
import cn.shangyu.gdxzExpert.view.CommonProgressDialog;
|
||||
import io.dcloud.feature.sdk.DCUniMPSDK;
|
||||
import io.dcloud.feature.sdk.Interface.IUniMP;
|
||||
import io.dcloud.feature.unimp.config.IUniMPReleaseCallBack;
|
||||
import io.dcloud.feature.unimp.config.UniMPOpenConfiguration;
|
||||
import io.dcloud.feature.unimp.config.UniMPReleaseConfiguration;
|
||||
|
||||
public class UniappUtil {
|
||||
|
||||
/**
|
||||
* 展示uniapp mp - 公共方法
|
||||
* @param context 上下文
|
||||
* @param targetPath
|
||||
*/
|
||||
public static void showUniMp(Context context, String targetPath, com.alibaba.fastjson.JSONObject pageParams) {
|
||||
try {
|
||||
|
||||
checkWgt(context, targetPath, pageParams);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//打开小程序
|
||||
public static void show(Context context, String targetPath, com.alibaba.fastjson.JSONObject pageParams) {
|
||||
try {
|
||||
// 确保在主线程中执行,避免在后台线程中创建 Handler 导致异常
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
// 已经在主线程,直接执行
|
||||
showInternal(context, targetPath, pageParams);
|
||||
} else {
|
||||
// 不在主线程,切换到主线程执行
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showInternal(context, targetPath, pageParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void showInternal(Context context, String targetPath, com.alibaba.fastjson.JSONObject pageParams) {
|
||||
try {
|
||||
String uuid = SharePrefUtil.getString(context, Constant.uuid, "");
|
||||
if(StringUtil.isEmpty(uuid)){
|
||||
return;
|
||||
}
|
||||
String access_token = SharePrefUtil.getString(context, "access_token", "");
|
||||
String QueryString = StringUtil.toQueryString(pageParams);
|
||||
JSONObject userInfo = new JSONObject();
|
||||
userInfo.put("uuid", SharePrefUtil.getString(context, Constant.uuid, ""));
|
||||
userInfo.put("realName", SharePrefUtil.getString(context, Constant.realName, ""));
|
||||
userInfo.put("mobile", SharePrefUtil.getString(context, "mobile", ""));
|
||||
userInfo.put("photo", SharePrefUtil.getString(context, Constant.photo, ""));
|
||||
userInfo.put("qrcode", SharePrefUtil.getString(context, "qrcode", ""));
|
||||
userInfo.put("hospitalUuid", SharePrefUtil.getString(context, "hospitalUuid", ""));
|
||||
userInfo.put("hospitalName", SharePrefUtil.getString(context, "hospitalName", ""));
|
||||
userInfo.put("officeUuid", SharePrefUtil.getString(context, "officeUuid", ""));
|
||||
userInfo.put("officeName", SharePrefUtil.getString(context, "officeName", ""));
|
||||
userInfo.put("officePhone", SharePrefUtil.getString(context, "officePhone", ""));
|
||||
userInfo.put("positionUuid", SharePrefUtil.getString(context, "positionUuid", ""));
|
||||
userInfo.put("positionName", SharePrefUtil.getString(context, "positionName", ""));
|
||||
|
||||
try {
|
||||
userInfo.put("isStar", SharePrefUtil.getString(context, "isStar", ""));
|
||||
}catch (Exception e){
|
||||
userInfo.put("isStar", SharePrefUtil.getInt(context, "isStar", 0));
|
||||
}
|
||||
|
||||
String app_version = UpdateVersionUtils.getVersionName();
|
||||
UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration();
|
||||
uniMPOpenConfiguration.splashClass = UniappSplashView.class;
|
||||
uniMPOpenConfiguration.extraData.put("darkmode", "light");
|
||||
uniMPOpenConfiguration.extraData.put("apiHost", url_path);
|
||||
uniMPOpenConfiguration.extraData.put("token", access_token);
|
||||
uniMPOpenConfiguration.extraData.put("app_version", app_version);
|
||||
uniMPOpenConfiguration.extraData.put("userInfo", userInfo);
|
||||
|
||||
IUniMP uniapp_MP_cash = BaseApplication.getUniMPCaches().get(uniapp_mp_appid);
|
||||
|
||||
Log.d("UniappUtil","uniapp_MP_cash="+uniapp_MP_cash);
|
||||
if(uniapp_MP_cash != null){
|
||||
Log.d("UniappUtil","uniapp_MP_cash.isRunning()="+uniapp_MP_cash.isRunning());
|
||||
}
|
||||
//存在但是不在运行
|
||||
if(uniapp_MP_cash != null && !uniapp_MP_cash.isRunning()){
|
||||
BaseApplication.getUniMPCaches().remove(uniapp_mp_appid);
|
||||
uniapp_MP_cash.closeUniMP();
|
||||
}
|
||||
|
||||
if(uniapp_MP_cash != null && uniapp_MP_cash.isRunning()){
|
||||
uniapp_MP_cash.sendUniMPEvent("goPage", targetPath+QueryString);
|
||||
uniapp_MP_cash.showUniMP();
|
||||
}else{
|
||||
if(StringUtil.notEmpty(targetPath)){
|
||||
uniMPOpenConfiguration.extraData.put("targetPath", targetPath+QueryString);
|
||||
}
|
||||
// 优先使用传入的context(如果是Activity),否则使用mContext
|
||||
Context openContext = context;
|
||||
if (!(openContext instanceof android.app.Activity)) {
|
||||
// 如果传入的不是Activity,尝试从AppManager获取当前Activity
|
||||
android.app.Activity currentActivity = cn.shangyu.gdxzExpert.base.AppManager.getAppManager().currentActivity();
|
||||
if (currentActivity != null) {
|
||||
openContext = currentActivity;
|
||||
} else {
|
||||
// 如果还是获取不到,使用mContext作为fallback
|
||||
openContext = mContext;
|
||||
}
|
||||
}
|
||||
IUniMP uniapp_MP = DCUniMPSDK.getInstance().openUniMP(openContext, uniapp_mp_appid, uniMPOpenConfiguration);
|
||||
BaseApplication.getUniMPCaches().put(uniapp_MP.getAppid(), uniapp_MP);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeUniMP(){
|
||||
IUniMP uniapp_MP = BaseApplication.getUniMPCaches().get(uniapp_mp_appid);
|
||||
if(uniapp_MP != null && uniapp_MP.isRunning()){
|
||||
uniapp_MP.closeUniMP();
|
||||
BaseApplication.getUniMPCaches().remove(uniapp_mp_appid);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkWgt(Context context, String targetPath, com.alibaba.fastjson.JSONObject pageParams) throws JSONException {
|
||||
|
||||
JSONObject jsonObject = DCUniMPSDK.getInstance().getAppVersionInfo(uniapp_mp_appid);
|
||||
if(jsonObject != null) {
|
||||
Integer current_version_code = Integer.parseInt(jsonObject.getString("code"));
|
||||
Log.d("checkWgt",current_version_code+",当前版本");
|
||||
HttpMD5SendInfoUtil.sendHttp(Url.checkUniappWgt, null, new OnCallBackFromNet() {
|
||||
@Override
|
||||
public void onCallbackFromThread(String resultJson) {
|
||||
Log.d("checkWgt",resultJson);
|
||||
UniappMpCheckWgt checkWgt = GsonTools.fromGsonToBean(resultJson,UniappMpCheckWgt.class);
|
||||
if(checkWgt.getData() != null){
|
||||
Log.d("checkWgt", checkWgt.getData().toString());
|
||||
Integer new_version_code = checkWgt.getData().getVersion_code();
|
||||
if(new_version_code != null && new_version_code > current_version_code){
|
||||
Log.d("checkWgt", "去更新");
|
||||
updateWgt(context, uniapp_mp_appid, checkWgt.getData().getUrl(), targetPath, pageParams);
|
||||
}else{
|
||||
Log.d("checkWgt", "直接打开");
|
||||
//真正打开小程序
|
||||
show(context, targetPath, pageParams);
|
||||
}
|
||||
}else{
|
||||
//真正打开小程序
|
||||
show(context, targetPath, pageParams);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onCallBackFromThread(String resultJson, int resultCode) {
|
||||
|
||||
}
|
||||
});
|
||||
}else{
|
||||
//真正打开小程序
|
||||
show(context, targetPath, pageParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 热更新uniapp小程序
|
||||
*/
|
||||
private static void updateWgt(Context context, String uniapp_appid, String wgtUrl, String targetPath, com.alibaba.fastjson.JSONObject pageParams) {
|
||||
// 替换真实的下载地址
|
||||
final String wgtName = uniapp_appid + ".wgt";
|
||||
String downFilePath = context.getExternalCacheDir().getPath();
|
||||
// 确保使用主线程的 Looper 创建 Handler,避免在子线程中直接 new Handler() 导致异常
|
||||
Handler uiHandler = new Handler(Looper.getMainLooper());
|
||||
// 使用 final 数组来存储对话框引用,以便在内部类中访问
|
||||
final CommonProgressDialog[] progressDialogRef = new CommonProgressDialog[1];
|
||||
|
||||
// 在主线程中创建和显示进度对话框
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CommonProgressDialog progressDialog = new CommonProgressDialog(context);
|
||||
progressDialog.setMessage("更新中");
|
||||
progressDialog.setMax(100);
|
||||
progressDialog.setProgress(0);
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
progressDialogRef[0] = progressDialog;
|
||||
}
|
||||
});
|
||||
|
||||
UniappDownloadUtil.get().download(context, wgtUrl, downFilePath, wgtName, new UniappDownloadUtil.OnDownloadListener() {
|
||||
@Override
|
||||
public void onDownloadSuccess(File file) {
|
||||
UniMPReleaseConfiguration uniMPReleaseConfiguration = new UniMPReleaseConfiguration();
|
||||
uniMPReleaseConfiguration.wgtPath = file.getPath();
|
||||
// 没有密码可以不写
|
||||
// uniMPReleaseConfiguration.password = "789456123";
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 关闭进度对话框
|
||||
if (progressDialogRef[0] != null && progressDialogRef[0].isShowing()) {
|
||||
progressDialogRef[0].dismiss();
|
||||
}
|
||||
DCUniMPSDK.getInstance().releaseWgtToRunPath(uniapp_appid, uniMPReleaseConfiguration, new IUniMPReleaseCallBack() {
|
||||
@Override
|
||||
public void onCallBack(int code, Object pArgs) {
|
||||
if(code ==1) {
|
||||
//释放wgt完成
|
||||
try {
|
||||
IUniMP uniMP = BaseApplication.getUniMPCaches().get(uniapp_appid);
|
||||
if(uniMP != null && uniMP.isRunning()){
|
||||
uniMP.closeUniMP();
|
||||
}
|
||||
|
||||
//打开小程序
|
||||
show(context, targetPath, pageParams);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else{
|
||||
//释放wgt失败
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloading(int progress) {
|
||||
// Log.i("checkWgt", progress+"");
|
||||
final int finalProgress = progress;
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 更新进度对话框
|
||||
if (progressDialogRef[0] != null && progressDialogRef[0].isShowing()) {
|
||||
progressDialogRef[0].setProgress(finalProgress);
|
||||
progressDialogRef[0].setMessage("更新中,请稍后");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadFailed() {
|
||||
Log.e("unimp", "downFilePath === onDownloadFailed");
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 关闭进度对话框
|
||||
if (progressDialogRef[0] != null && progressDialogRef[0].isShowing()) {
|
||||
progressDialogRef[0].dismiss();
|
||||
}
|
||||
// 显示失败提示
|
||||
ToastUtil.showToast("小程序更新失败,请稍后重试");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -722,5 +722,6 @@ public static String getInteractionListByTag = urlmyLan
|
||||
public static String checkUser=urlmyLan+"checkUser";//检查账户
|
||||
|
||||
|
||||
public static String checkUniappWgt = urlmyLan + "checkUniappWgt";//检查小程序版本
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user