Althars123 4 жил өмнө
parent
commit
e9c4c7df81

+ 68 - 4
zzjs-admin/src/main/java/com/miaxis/app/controller/film/FilmController.java

@@ -14,6 +14,7 @@ import com.miaxis.common.utils.SecurityUtils;
 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;
@@ -21,18 +22,23 @@ import io.swagger.annotations.ApiOperation;
 import lombok.Data;
 import lombok.RequiredArgsConstructor;
 import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 
 /**
  * 【小程序-客户信息】Controller
@@ -89,5 +95,63 @@ public class FilmController extends BaseController {
     }
 
 
+    /**
+     * 以form表单形式提交数据,发送post请求
+     * @explain
+     *   1.请求头:httppost.setHeader("Content-Type","application/x-www-form-urlencoded")
+     *   2.提交的数据格式:key1=value1&key2=value2...
+     * @return 服务器返回数据
+     */
+    @PostMapping(value = "/fileCommonApi")
+    @ApiOperation("微信支付获取预订单id")
+    public static String httpPostWithForm(FilmDTO filmDTO){
+        // 用于接收返回的结果
+        String resultData ="";
+        try {
+            HttpPost post = new HttpPost("http://movieapi2-test.taototo.cn/"+filmDTO.getUrl());
+            post.setHeader("Content-Type","application/x-www-form-urlencoded");
+            // 创建一个http客户端
+            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+            // 发送post请求
+            HttpResponse response = httpClient.execute(post);
+
+            // 状态码为:200
+            if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
+                // 返回数据:
+                resultData = EntityUtils.toString(response.getEntity(),"UTF-8");
+            }else{
+                throw new RuntimeException("接口连接失败!");
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("接口连接失败!");
+        }
+        return 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();
+    }
+
+
+
+
+
+
+
+
 
 }

+ 1 - 0
zzjs-admin/src/test/java/com/miaxis/test/NormalTest2.java

@@ -57,6 +57,7 @@ public class NormalTest2 {
         param.put("appKey",appKey);
         param.put("time",time);
         String sign = getSign(param,appSecret2);
+        System.out.println(sign);
         String md5 = MD5Utils.MD5Encode(sign);
         System.out.println(md5);
 

+ 0 - 1
zzjs-common/src/main/java/com/miaxis/common/config/BeanConfig.java

@@ -70,7 +70,6 @@ public class BeanConfig {
 
     @Bean
     public HttpClient wxpayConfigBean() throws Exception{
-        ClassPathResource classPathResource = new ClassPathResource("");
         File file = new ClassPathResource("wechatpay/apiclient_key.pem").getFile();
         String realPath =file.getAbsolutePath();
         PrivateKey privateKey = getPrivateKey(realPath);

+ 13 - 0
zzjs-service/src/main/java/com/miaxis/feign/dto/FilmDTO.java

@@ -0,0 +1,13 @@
+package com.miaxis.feign.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class FilmDTO {
+    @ApiModelProperty("请求url")
+    String url;
+    @ApiModelProperty("请求参数,key1=value1&key2=value2...的格式")
+    String paramData;
+
+}