欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

笔记

程序员文章站 2022-07-12 21:10:15
...
//登录
    @POST("small/user/v1/login")
    @FormUrlEncoded
    Observable<Result<UserBean>> login(@Field("phone")String phone,@Field("pwd")String pwd);
    //注册
    @POST("small/user/v1/register")
    @FormUrlEncoded
    Observable<Result> register(@Field("phone")String phone,@Field("pwd")String pwd);
    //轮播图
    @GET("small/commodity/v1/bannerShow")
    //@FormUrlEncoded
    Observable<Result<List<BannerBean>>> banner();
    //首页展示
    @GET("small/commodity/v1/commodityList")
    Observable<Result<HomeBean>> home();
    //商品一级列表
    @GET("small/commodity/v1/findFirstCategory")
    Observable<Result<List<LabelListBean>>> oneLabel();
    //商品二级列表
    @GET("small/commodity/v1/findSecondCategory")
    Observable<Result<List<LabelListBean>>> twoLabel(@Query("firstCategoryId")String firstCategoryId);
    //列表查询
    @GET("small/commodity/v1/findCommodityByCategory")
    Observable<Result<List<LabelBean>>> label(@Query("categoryId")String categoryId,@Query("page")int page,@Query("count")int count);
    //
    @GET("small/commodity/v1/CommodityCommentList")
    Observable<Result<List<ReviewBean>>> review(@Query("commodityId")int commodityId, @Query("page")int page, @Query("count")int count);
    //关键字查询
    @GET("small/commodity/v1/findCommodityByKeyword")
    Observable<Result<List<LabelBean>>> find(@Query("keyword")String keyword,@Query("page")int page,@Query("count")int count);
    @GET("small/commodity/v1/findCommodityDetailsById")
    Observable<Result<DetailsBean>> findsCommodity(@Header("userId")int userId, @Header("sessionId")String sessionId, @Query("commodityId")int commodityId);
    //查询圈子
    @GET("small/circle/v1/findCircleList")
    Observable<Result<List<CircleListBean>>> circleList(@Header("userId")long userId, @Header("sessionId")String sessionId, @Query("page")int page, @Query("count")int count);
    //点赞
    @POST("small/circle/verify/v1/addCircleGreat")
    @FormUrlEncoded
    Observable<Result> addCircleGreat(@Header("userId")long userId, @Header("sessionId")String sessionId, @Field("circleId") int circleId);
    //取消点赞
    @DELETE("small/circle/verify/v1/cancelCircleGreat")
    Observable<Result> cancelCircleGreat(@Header("userId")long userId, @Header("sessionId")String sessionId, @Query("circleId") int circleId);
    //查询购物车
    @GET("small/order/verify/v1/findShoppingCart")
    Observable<Result<List<ShoppingBean>>> findShopping(@Header("userId")int userId, @Header("sessionId")String sessionId);
    //同步购物车
    @PUT("small/order/verify/v1/syncShoppingCart")
    @FormUrlEncoded
     Observable<Result> syncShopping(@Header("userId")long userId, @Header("sessionId")String sessionId,@Field("data") String data);
    //创建订单
    @POST("small/order/verify/v1/createOrder")
    @FormUrlEncoded
     Observable<Result> createOrder(@Header("userId")long userId, @Header("sessionId")String sessionId,@Field("orderInfo") String orderInfo,@Field("totalPrice")double totalPrice,@Field("addressId")int addressId);
    //修改头像
    @POST("small/user/verify/v1/modifyHeadPic")
    Observable<Result> modifyHeadPic(@Header("userId")long userId, @Header("sessionId")String sessionId, @Body MultipartBody body);
    //需改昵称
    @PUT("small/user/verify/v1/modifyUserNick")
    @FormUrlEncoded
    Observable<Result> modifyUserNick(@Header("userId")long userId, @Header("sessionId")String sessionId, @Field("nickName") String nickName);
    //修改密码
    @PUT("small/user/verify/v1/modifyUserPwd")
    @FormUrlEncoded
    Observable<Result> modifyUserPwd(@Header("userId")long userId, @Header("sessionId")String sessionId, @Field("oldPwd") String oldPwd,@Field("newPwd") String newPwd);

    //添加地址
    @POST("small/user/verify/v1/addReceiveAddress")
    @FormUrlEncoded
    Observable<Result> addAddress(@Header("userId") long userId,
                                 @Header("sessionId") String sessionId,
                                 @Field("realName") String realName,
                                 @Field("phone") String phone,
                                 @Field("address") String address,
                                 @Field("zipCode") String zipCode);

    //查询地址
    @GET("small/user/verify/v1/receiveAddressList")
    Observable<Result<List<AddressBean>>> addresslist(@Header("userId") long userId, @Header("sessionId") String sessionId);

    @GET("small/commodity/verify/v1/browseList")
    Observable<Result<List<FootBean>>> browseList(@Header("userId")long userId, @Header("sessionId")String sessionId, @Query("page")int page, @Query("count")int count);
    //我的钱包
    @GET("small/user/verify/v1/findUserWallet")
    Observable<Result<UserWallet>> findUserWallet(@Header("userId")long userId, @Header("sessionId")String sessionId, @Query("page")int page, @Query("count")int count);
    //根据订单状态查询订单信息
    @GET("small/order/verify/v1/findOrderListByStatus")
    Observable<Result<AllListBean>> findOrderListByStatus(@Header("userId")long userId, @Header("sessionId")String sessionId,@Query("status")int status, @Query("page")int page, @Query("count")int count);
    //删除订单
    @DELETE("small/order/verify/v1/deleteOrder")
    Observable<Result> deleteOrder(@Header("userId")long userId, @Header("sessionId")String sessionId,@Query("orderId")String orderId);
    //收货
    @PUT("small/order/verify/v1/confirmReceipt")
    Observable<Result> confirmReceipt(@Header("userId")long userId, @Header("sessionId")String sessionId,@Query("orderId")String orderId);
    //支付
    @POST("small/order/verify/v1/pay")
    @FormUrlEncoded
    Observable<Result> pay(@Header("userId")long userId, @Header("sessionId")String sessionId,@Field("orderId") String orderId,@Field("payType")int payType);


     //发布圈子

    @POST("small/circle/verify/v1/releaseCircle")
    Observable<Result> releaseCircle(@Header("userId") long userId,
                                     @Header("sessionId")String sessionId,
                                     @Body MultipartBody body);
    //发布评价

    @POST("small/commodity/verify/v1/addCommodityComment")
    Observable<Result> addCommodityComment(@Header("userId") long userId,
                                     @Header("sessionId")String sessionId,
                                     @Body MultipartBody body);
File file = new File((String)objects[2]);
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
// builder.addFormDataPart("content", (String)args[4]);
        builder.addFormDataPart("image", file.getName(),
                RequestBody.create(MediaType.parse("multipart/octet-stream"),file));
        return iLoad.modifyHeadPic((long)objects[0],(String)objects[1],builder.build());

 

package com.example.shopping_lx.utils;

import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;
import android.provider.MediaStore;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author dingtao
 * @date 2018/12/7 15:06
 * qq:1940870847
 */
public class StringUtil {

    public static boolean isPhone(String phone) {
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
        if (phone.length() != 11) {
            return false;
        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phone);
            boolean isMatch = m.matches();
            return isMatch;
        }
    }

    /**
     * 根据Uri获取图片的绝对路径
     *
     * @param context 上下文对象
     * @param uri     图片的Uri
     * @return 如果Uri对应的图片存在, 那么返回该图片的绝对路径, 否则返回null
     */
    public static String getRealPathFromUri(Context context, Uri uri) {
        int sdkVersion = Build.VERSION.SDK_INT;
        if (sdkVersion >= 19) { // api >= 19
            return getRealPathFromUriAboveApi19(context, uri);
        } else { // api < 19
            return getRealPathFromUriBelowAPI19(context, uri);
        }
    }

    /**
     * 适配api19以下(不包括api19),根据uri获取图片的绝对路径
     *
     * @param context 上下文对象
     * @param uri     图片的Uri
     * @return 如果Uri对应的图片存在, 那么返回该图片的绝对路径, 否则返回null
     */
    private static String getRealPathFromUriBelowAPI19(Context context, Uri uri) {
        return getDataColumn(context, uri, null, null);
    }

    /**
     * 适配api19及以上,根据uri获取图片的绝对路径
     *
     * @param context 上下文对象
     * @param uri     图片的Uri
     * @return 如果Uri对应的图片存在, 那么返回该图片的绝对路径, 否则返回null
     */
    private static String getRealPathFromUriAboveApi19(Context context, Uri uri) {
        String filePath = null;
        if (DocumentsContract.isDocumentUri(context, uri)) {
            // 如果是document类型的 uri, 则通过document id来进行处理
            String documentId = DocumentsContract.getDocumentId(uri);
            if (isMediaDocument(uri)) { // MediaProvider
                // 使用':'分割
                String id = documentId.split(":")[1];

                String selection = MediaStore.Images.Media._ID + "=?";
                String[] selectionArgs = {id};
                filePath = getDataColumn(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection, selectionArgs);
            } else if (isDownloadsDocument(uri)) { // DownloadsProvider
                Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(documentId));
                filePath = getDataColumn(context, contentUri, null, null);
            }
        } else if ("content".equalsIgnoreCase(uri.getScheme())) {
            // 如果是 content 类型的 Uri
            filePath = getDataColumn(context, uri, null, null);
        } else if ("file".equals(uri.getScheme())) {
            // 如果是 file 类型的 Uri,直接获取图片对应的路径
            filePath = uri.getPath();
        }
        return filePath;
    }

    /**
     * 获取数据库表中的 _data 列,即返回Uri对应的文件路径
     *
     * @return
     */
    private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
        String path = null;

        String[] projection = new String[]{MediaStore.Images.Media.DATA};
        Cursor cursor = null;
        try {
            cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
            if (cursor != null && cursor.moveToFirst()) {
                int columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
                path = cursor.getString(columnIndex);
            }
        } catch (Exception e) {
            if (cursor != null) {
                cursor.close();
            }
        }
        return path;
    }

    /**
     * @param uri the Uri to check
     * @return Whether the Uri authority is MediaProvider
     */
    private static boolean isMediaDocument(Uri uri) {
        return "com.android.providers.media.documents".equals(uri.getAuthority());
    }

    /**
     * @param uri the Uri to check
     * @return Whether the Uri authority is DownloadsProvider
     */
    private static boolean isDownloadsDocument(Uri uri) {
        return "com.android.providers.downloads.documents".equals(uri.getAuthority());
    }
}
Bitmap bm = data.getParcelableExtra("data");
            Uri uri = BitmapToUri(getActivity(), bm);
            String path = StringUtil.getRealPathFromUri(getContext(), uri);


public static Uri BitmapToUri(Context c, Bitmap b) {
        File path = new File(c.getCacheDir() + File.separator + System.currentTimeMillis() + ".jpg");
        try {
            OutputStream os = new FileOutputStream(path);
            b.compress(Bitmap.CompressFormat.JPEG, 100, os);
            os.close();
            return Uri.fromFile(path);
        } catch (Exception ignored) {
        }
        return null;
    }

but_take_photos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path)));
                startActivityForResult(intent, PHOTO_REQUEST_CAREMA);
            }
        });
        but_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 = new Intent(Intent.ACTION_PICK);
                intent1.setType("image/*");
                // 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_GALLERY
                startActivityForResult(intent1, PHOTO_REQUEST_GALLERY);
                window.dismiss();
            }
        });

 

上一篇: 笔记

下一篇: 笔记