|
@@ -10,6 +10,7 @@ import com.miaxis.common.core.controller.BaseController;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
import com.miaxis.common.core.page.ResponsePageInfo;
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.sms.MD5Utils;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.common.utils.StringUtils;
|
|
@@ -18,10 +19,10 @@ import com.miaxis.customer.dto.AppletCustomerInfoDto;
|
|
|
import com.miaxis.customer.service.ICustomerInfoService;
|
|
|
import com.miaxis.customer.vo.ExhibitionCustomerInfoVo;
|
|
|
import com.miaxis.feign.dto.FilmDTO;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiImplicitParam;
|
|
|
-import io.swagger.annotations.ApiImplicitParams;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
+import com.miaxis.film.domain.FilmOrder;
|
|
|
+import com.miaxis.film.dto.FilmOrderCreateDTO;
|
|
|
+import com.miaxis.film.service.IFilmOrderService;
|
|
|
+import io.swagger.annotations.*;
|
|
|
import lombok.Data;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.commons.lang.RandomStringUtils;
|
|
@@ -38,6 +39,7 @@ import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
@@ -46,6 +48,8 @@ import java.security.PrivateKey;
|
|
|
import java.security.Signature;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
|
|
|
+
|
|
|
/**
|
|
|
* 【小程序-客户信息】Controller
|
|
|
*
|
|
@@ -64,21 +68,26 @@ public class FilmController extends BaseController {
|
|
|
@Autowired
|
|
|
private WxpayConfig wxpayConfig;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IFilmOrderService filmOrderService;
|
|
|
+
|
|
|
@Value("${app.appid}")
|
|
|
private String appid;
|
|
|
-
|
|
|
- private static String appKey = "10000000000";
|
|
|
-
|
|
|
- private static String appSecret = "25f9e794323b453885f5181f1b624d0b";
|
|
|
+ @Value("${film.appKey}")
|
|
|
+ private String appKey ;
|
|
|
+ @Value("${film.appSecret}")
|
|
|
+ private String appSecret ;
|
|
|
+ @Value("${film.notifyUrl}")
|
|
|
+ private String notifyUrl ;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 微信支付获取预订单id
|
|
|
*/
|
|
|
- @GetMapping(value = "/prepareOrder")
|
|
|
+ @PostMapping(value = "/prepareOrder")
|
|
|
@ApiOperation("微信支付获取预订单id")
|
|
|
- public Response<JSONObject> getPrepareOrderId() throws Exception{
|
|
|
+ public Response<JSONObject> getPrepareOrderId(@RequestBody FilmOrderCreateDTO filmOrderCreateDTO) throws Exception{
|
|
|
HttpPost httpPost = new HttpPost(wxpayConfig.getV3url());
|
|
|
httpPost.addHeader("Accept", "application/json");
|
|
|
httpPost.addHeader("Content-type","application/json; charset=utf-8");
|
|
@@ -86,20 +95,44 @@ public class FilmController extends BaseController {
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
+ //生成订单id
|
|
|
+ UserInfo student = SecurityUtils.getLoginUser().getStudent();
|
|
|
+ Long id = student.getId();
|
|
|
+ String orderCode = getOrderCode(id);
|
|
|
+ System.out.println(appid);
|
|
|
+ System.out.println(notifyUrl);
|
|
|
+
|
|
|
+ //生成预订单
|
|
|
ObjectNode rootNode = objectMapper.createObjectNode();
|
|
|
- rootNode.put("mchid","1608699504")
|
|
|
- .put("appid", "wx8f43db501343feab")
|
|
|
- .put("description", "Image形象店-深圳腾大-QQ公仔")
|
|
|
- .put("notify_url", "https://www.weixin.qq.com/wxpay/pay.php")
|
|
|
- .put("out_trade_no", "1217752501201407033233368044");
|
|
|
+ rootNode.put("mchid",wxpayConfig.getMerchantId())
|
|
|
+ .put("appid", appid)
|
|
|
+ .put("description", "电影票")
|
|
|
+ .put("notify_url", notifyUrl)
|
|
|
+ .put("out_trade_no", orderCode);
|
|
|
rootNode.putObject("amount")
|
|
|
- .put("total", 1);
|
|
|
+ .put("total", filmOrderCreateDTO.getTotal());
|
|
|
rootNode.putObject("payer")
|
|
|
- .put("openid", "oO7PJ5FlradAM7tqw3TM2zvEj4O4");
|
|
|
+ .put("openid", student.getOpenid());
|
|
|
objectMapper.writeValue(bos, rootNode);
|
|
|
httpPost.setEntity(new StringEntity(bos.toString("UTF-8")));
|
|
|
HttpResponse response = httpClient.execute(httpPost);
|
|
|
String bodyAsString = EntityUtils.toString(response.getEntity());
|
|
|
+ System.out.println(bodyAsString);
|
|
|
+ if (JSONObject.parseObject(bodyAsString).get("prepay_id") == null){
|
|
|
+ throw new CustomException(JSONObject.parseObject(bodyAsString).get("message").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //本地创建订单
|
|
|
+ FilmOrder order = new FilmOrder();
|
|
|
+ order.setOutTradeNo(orderCode);
|
|
|
+ order.setSeat(filmOrderCreateDTO.getSeat());
|
|
|
+ order.setAcceptChangeSeat(filmOrderCreateDTO.getAcceptChangeSeat());
|
|
|
+ order.setSeatId(filmOrderCreateDTO.getSeatId());
|
|
|
+ order.setSeatno(filmOrderCreateDTO.getSeatno());
|
|
|
+ order.setReservedPhone(filmOrderCreateDTO.getReservedPhone());
|
|
|
+ filmOrderService.save(order);
|
|
|
+
|
|
|
+
|
|
|
String packageStr = "prepay_id="+JSONObject.parseObject(bodyAsString).get("prepay_id");
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("package",packageStr);
|
|
@@ -147,7 +180,6 @@ public class FilmController extends BaseController {
|
|
|
post.setHeader("Content-Type","application/x-www-form-urlencoded");
|
|
|
Map<String, Object> sortMap = new TreeMap<String, Object>();
|
|
|
String time = String.valueOf(System.currentTimeMillis()/1000);
|
|
|
- Map<String,Object> param = new HashMap<String,Object>();
|
|
|
sortMap.put("appKey",appKey);
|
|
|
sortMap.put("time",time);
|
|
|
//1 将数据拆分成 treemap存储
|
|
@@ -165,8 +197,9 @@ public class FilmController extends BaseController {
|
|
|
Object v = s.getValue();
|
|
|
builder.append(k).append("=").append(v).append("&");
|
|
|
}
|
|
|
+ builder.append("appSecret="+appSecret);
|
|
|
//3 将最后拼接出来的sign传 md5加密
|
|
|
- String sign = MD5Utils.MD5Encode(builder.append("appSecret="+appSecret).toString());
|
|
|
+ String sign = MD5Utils.MD5Encode(builder.toString());
|
|
|
List<BasicNameValuePair> pairList = new ArrayList<BasicNameValuePair>();
|
|
|
// 迭代Map-->取出key,value放到BasicNameValuePair对象中-->添加到list中
|
|
|
for (Map.Entry entry : sortMap.entrySet()) {
|
|
@@ -194,22 +227,16 @@ public class FilmController extends BaseController {
|
|
|
return Response.success(JSONObject.parseObject(resultData));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public static String getSign(Map<String, Object> params,String appSecretStr) {
|
|
|
- Map<String, Object> sortMap = new TreeMap<String, Object>();
|
|
|
- sortMap.putAll(params);
|
|
|
- // 以k1=v1&k2=v2...方式拼接参数
|
|
|
- StringBuilder builder = new StringBuilder();
|
|
|
- for (Map.Entry<String, Object> s : sortMap.entrySet()) {
|
|
|
- String k = s.getKey();
|
|
|
- Object v = s.getValue();
|
|
|
- builder.append(k).append("=").append(v).append("&");
|
|
|
- }
|
|
|
- if (!sortMap.isEmpty()) {
|
|
|
- builder.deleteCharAt(builder.length() - 1);
|
|
|
- }
|
|
|
- builder.append(appSecretStr);
|
|
|
- return builder.toString();
|
|
|
+ /**
|
|
|
+ * 获取电影订单详细信息
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/{id}")
|
|
|
+ @ApiOperation("获取电影订单详细信息")
|
|
|
+ public Response<FilmOrder> getInfo(
|
|
|
+ @ApiParam(name = "id", value = "电影订单参数", required = true)
|
|
|
+ @PathVariable("id") Long id
|
|
|
+ ){
|
|
|
+ return Response.success(filmOrderService.getById(id));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -223,4 +250,7 @@ public class FilmController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|