@ -0,0 +1,52 @@
|
|||||||
|
package com.orangesale.cn.entity;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class OrangeMessage {
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getSendTime() {
|
||||||
|
return sendTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSendTime(Timestamp sendTime) {
|
||||||
|
this.sendTime = sendTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsed() {
|
||||||
|
return used;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsed(String used) {
|
||||||
|
this.used = used;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private String content;
|
||||||
|
private Timestamp sendTime;
|
||||||
|
private String used;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "OrangeMessage{" +
|
||||||
|
"id=" + id +
|
||||||
|
", content='" + content + '\'' +
|
||||||
|
", sendTime=" + sendTime +
|
||||||
|
", used='" + used + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.orangesale.cn.entity;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class OrangeProduct {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private BigDecimal price;
|
||||||
|
private String imgUrl;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "OrangeProduct{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", price=" + price +
|
||||||
|
", imgUrl='" + imgUrl + '\'' +
|
||||||
|
", addTime=" + addTime +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getAddTime() {
|
||||||
|
return addTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddTime(Timestamp addTime) {
|
||||||
|
this.addTime = addTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Timestamp addTime;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(BigDecimal price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImgUrl() {
|
||||||
|
return imgUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImgUrl(String imgUrl) {
|
||||||
|
this.imgUrl = imgUrl;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package com.orangesale.cn.entity;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class OrangeProductPack {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Timestamp addTime;
|
||||||
|
private Bitmap imgBitmap;
|
||||||
|
|
||||||
|
public BigDecimal getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(BigDecimal price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal price;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "OrangeProductPack{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", addTime=" + addTime +
|
||||||
|
", imgBitmap=" + imgBitmap +
|
||||||
|
", price=" + price +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getAddTime() {
|
||||||
|
return addTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddTime(Timestamp addTime) {
|
||||||
|
this.addTime = addTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getImgBitmap() {
|
||||||
|
return imgBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImgBitmap(Bitmap imgBitmap) {
|
||||||
|
this.imgBitmap = imgBitmap;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
package com.orangesale.cn.netrequest;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.TypeReference;
|
||||||
|
import com.orangesale.cn.entity.OrangeProduct;
|
||||||
|
import com.orangesale.cn.entity.OrangeProductPack;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
public class OkHttpClientProduct {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询商品信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<OrangeProduct> getProduct() throws IOException {
|
||||||
|
OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url("http://172.16.40.55:8081/orange/product/search")
|
||||||
|
.build();
|
||||||
|
Response response = okHttpClient.newCall(request).execute();
|
||||||
|
JSONObject jsonObject = JSON.parseObject(Objects.requireNonNull(response.body()).string());
|
||||||
|
List<OrangeProduct> list = JSON.parseObject(jsonObject.getString("data"), new TypeReference<List<OrangeProduct>>() {
|
||||||
|
});
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图片
|
||||||
|
*
|
||||||
|
* @param imgUrl
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public Bitmap getImageBitMap(String imgUrl) throws IOException {
|
||||||
|
Bitmap bitmap;
|
||||||
|
OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(imgUrl)
|
||||||
|
.build();
|
||||||
|
Response response = okHttpClient.newCall(request).execute();
|
||||||
|
byte[] bytes = Objects.requireNonNull(response.body()).bytes();
|
||||||
|
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
||||||
|
return bitmap;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
|
||||||
|
public List<OrangeProductPack> getProductPack() throws IOException {
|
||||||
|
List<OrangeProductPack> packList = new ArrayList<>();
|
||||||
|
List<OrangeProduct> list = getProduct();
|
||||||
|
for (OrangeProduct orangeProduct : list) {
|
||||||
|
OrangeProductPack orangeProductPack = new OrangeProductPack();
|
||||||
|
orangeProductPack.setId(orangeProduct.getId());
|
||||||
|
orangeProductPack.setImgBitmap(getImageBitMap(orangeProduct.getImgUrl()));
|
||||||
|
orangeProductPack.setAddTime(orangeProduct.getAddTime());
|
||||||
|
orangeProductPack.setPrice(orangeProduct.getPrice());
|
||||||
|
packList.add(orangeProductPack);
|
||||||
|
}
|
||||||
|
return packList;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.orangesale.cn.netrequest;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.orangesale.cn.entity.OrangeUser;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
public class OkHttpUser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户登录验证
|
||||||
|
*
|
||||||
|
* @param orangeUser
|
||||||
|
*/
|
||||||
|
public OrangeUser userLogin(OrangeUser orangeUser) throws IOException {
|
||||||
|
OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
//数据类型为json格式
|
||||||
|
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
||||||
|
//将对象转为JSON字符串
|
||||||
|
String jsonStr = JSONObject.toJSONString(orangeUser);
|
||||||
|
RequestBody requestBody = RequestBody.create(jsonStr, mediaType);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url("http://172.16.40.55:8081/orange/user/login")
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
Response response = okHttpClient.newCall(request).execute();
|
||||||
|
JSONObject jsonObject = JSON.parseObject(response.body().string());
|
||||||
|
JSONObject jsonObject1 = jsonObject.getJSONObject("data");
|
||||||
|
OrangeUser orangeUser1 = JSON.toJavaObject(jsonObject1, OrangeUser.class);
|
||||||
|
return orangeUser1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注册
|
||||||
|
*
|
||||||
|
* @param orangeUser
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public boolean userRegister(OrangeUser orangeUser) throws IOException {
|
||||||
|
OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
//数据类型为json格式
|
||||||
|
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
||||||
|
//将对象转为JSON字符串
|
||||||
|
String jsonStr = JSONObject.toJSONString(orangeUser);
|
||||||
|
RequestBody requestBody = RequestBody.create(jsonStr, mediaType);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url("http://172.16.40.55:8081/orange/user/register")
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
Response response = okHttpClient.newCall(request).execute();
|
||||||
|
JSONObject jsonObject = JSON.parseObject(response.body().string());
|
||||||
|
Log.i("register", "userRegister: "+jsonObject);
|
||||||
|
return jsonObject.getBoolean("flag");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 368 B After Width: | Height: | Size: 368 B |
Before Width: | Height: | Size: 231 B After Width: | Height: | Size: 231 B |
Before Width: | Height: | Size: 233 B After Width: | Height: | Size: 233 B |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 790 B After Width: | Height: | Size: 790 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 799 B After Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 402 B After Width: | Height: | Size: 402 B |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 554 B After Width: | Height: | Size: 554 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.3 KiB |