李天标 5 yıl önce
ebeveyn
işleme
19daba2ce8

+ 5 - 1
pom.xml

@@ -115,7 +115,11 @@
 			<artifactId>fastjson</artifactId>
 			<version>1.2.58</version>
 		</dependency>
-
+		<dependency>
+			<groupId>dom4j</groupId>
+			<artifactId>dom4j</artifactId>
+			<version>1.6.1</version>
+		</dependency>
 		<!-- swagger2 -->
 		<dependency>
 			<groupId>io.springfox</groupId>

+ 99 - 0
src/main/java/com/shawn/service/impl/TPromoCodeServiceImpl.java

@@ -1,14 +1,29 @@
 package com.shawn.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.shawn.model.entity.TPromoCode;
 import com.shawn.model.entity.TPromoCodeExample;
 import com.shawn.model.param.TPromoCodeParam;
 import com.shawn.repository.TPromoCodeMapper;
 import com.shawn.service.base.BaseService;
 import com.shawn.service.interfac.TPromoCodeServiceInterface;
+import com.shawn.util.HttpClientUtils;
+import com.shawn.util.JoinpayConstant;
+import org.apache.commons.codec.digest.DigestUtils;
+
+import org.apache.http.message.BasicNameValuePair;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 @Service
 public class TPromoCodeServiceImpl extends BaseService<TPromoCode, TPromoCodeExample, TPromoCodeParam,Integer> implements TPromoCodeServiceInterface {
     @Autowired
@@ -26,4 +41,88 @@ public class TPromoCodeServiceImpl extends BaseService<TPromoCode, TPromoCodeExa
     public Double findPrice() {
         return tPromoCodeMapper.findPrice();
     }
+
+    @Override
+    public String uniPay(String orderNo, BigDecimal amount, String productName, String productDesc, String commonParameter, String returnUrl, String notifyUrl, String frpCode, String isShowPic, String openId, String authCode, String appid, String transactionModel, String tradeMerchantNo, String buyerId, String isAlt, String altType, JSONArray altInfo, String altUrl, BigDecimal marketingAmount) {
+        String url = "https://www.joinpay.com/trade/uniPayApi.action";
+
+
+        List<BasicNameValuePair> data = new ArrayList<BasicNameValuePair>();
+
+
+
+        data.add(new BasicNameValuePair("p0_Version",JoinpayConstant.pay_version));
+        data.add(new BasicNameValuePair("p1_MerchantNo", JoinpayConstant.mch_no));
+        data.add(new BasicNameValuePair("p2_OrderNo", orderNo));
+        data.add(new BasicNameValuePair("p3_Amount", amount.setScale(2, RoundingMode.HALF_DOWN).toString()));
+        data.add(new BasicNameValuePair("p4_Cur", JoinpayConstant.Cur_RMB));
+        try {
+            data.add(new BasicNameValuePair("p5_ProductName", URLEncoder.encode(productName, "utf-8")));
+            data.add(new BasicNameValuePair("p6_ProductDesc", URLEncoder.encode(productDesc, "utf-8")));
+            data.add(new BasicNameValuePair("p7_Mp", URLEncoder.encode(commonParameter, "utf-8")));
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        data.add(new BasicNameValuePair("p8_ReturnUrl", returnUrl));
+        data.add(new BasicNameValuePair("p9_NotifyUrl", notifyUrl));
+        data.add(new BasicNameValuePair("q1_FrpCode", frpCode));
+        data.add(new BasicNameValuePair("q2_MerchantBankCode", ""));
+        data.add(new BasicNameValuePair("q4_IsShowPic", isShowPic));
+        data.add(new BasicNameValuePair("q5_OpenId", openId));
+        data.add(new BasicNameValuePair("q6_AuthCode", authCode));
+        data.add(new BasicNameValuePair("q7_AppId", appid));
+        data.add(new BasicNameValuePair("q8_TerminalNo", ""));
+        data.add(new BasicNameValuePair("q9_TransactionModel", transactionModel));
+        data.add(new BasicNameValuePair("qa_TradeMerchantNo", ""));
+        data.add(new BasicNameValuePair("qb_buyerId", buyerId));
+        data.add(new BasicNameValuePair("qc_IsAlt", isAlt));
+        data.add(new BasicNameValuePair("qd_AltType", altType));
+        data.add(new BasicNameValuePair("qe_AltInfo", altInfo==null?null:altInfo.toString()));
+        data.add(new BasicNameValuePair("qf_AltUrl", altUrl));
+
+        data.add(new BasicNameValuePair("qg_MarketingAmount", marketingAmount==null?null:marketingAmount.setScale(2, RoundingMode.HALF_DOWN).toString()));
+
+        // TODO: 2019-04-01  空值不参与签名!!!!!!!!!!!!!!!!!!
+
+
+        String hmac = null;
+        try {
+            hmac = createHmacSign(data, JoinpayConstant.key);
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        data.add(new BasicNameValuePair("hmac", hmac));
+//        logger.info("请求参数:" + data);
+
+        String result =  HttpClientUtils.postKeyValue(url, data);
+//        logger.info("响应参数:" + result);
+
+        return result;
+    }
+    /**
+     * 签名算法sign , hmac 签名
+     *
+     * @param data
+     * @return
+     */
+    public static String createHmacSign( List<BasicNameValuePair> data , String key) throws UnsupportedEncodingException {
+
+        StringBuffer sb = new StringBuffer();
+        Iterator<BasicNameValuePair> es = data.iterator();
+        while (es.hasNext()) {
+            BasicNameValuePair entry = (BasicNameValuePair) es.next();
+            String k = (String) entry.getName();
+            String v = (String) entry.getValue();
+            if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
+                sb.append(URLDecoder.decode(String.valueOf(v), "utf-8"));
+            }
+        }
+
+        sb.append(key);
+//        logger.info("签名字符串:" + sb.toString());
+        String sign = DigestUtils.md5Hex(sb.toString());
+        return sign;
+    }
+
 }

+ 6 - 0
src/main/java/com/shawn/service/interfac/TPromoCodeServiceInterface.java

@@ -1,11 +1,17 @@
 package com.shawn.service.interfac;
 
+import com.alibaba.fastjson.JSONArray;
 import com.shawn.model.entity.TPromoCode;
 import com.shawn.model.entity.TPromoCodeExample;
 import com.shawn.model.param.TPromoCodeParam;
 import com.shawn.service.base.BaseServiceInterface;
 
+import java.math.BigDecimal;
+
 public interface TPromoCodeServiceInterface extends BaseServiceInterface<TPromoCode, TPromoCodeExample, TPromoCodeParam,Integer>{
 
     Double findPrice();
+
+    String uniPay(String orderNo, BigDecimal amount, String productName, String productDesc, String commonParameter, String returnUrl, String notifyUrl, String frpCode, String isShowPic, String openId, String authCode, String appid, String transactionModel, String tradeMerchantNo, String buyerId, String isAlt, String altType, JSONArray altInfo, String altUrl, BigDecimal marketingAmount);
+
 }

+ 270 - 0
src/main/java/com/shawn/util/HttpClientUtils.java

@@ -0,0 +1,270 @@
+package com.shawn.util;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.config.SocketConfig;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLContexts;
+import org.apache.http.conn.ssl.TrustStrategy;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.io.SAXReader;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+import javax.net.ssl.SSLContext;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.List;
+
+/**
+ * Created by study on 6/26/2015 11:30.
+ */
+public final class HttpClientUtils {
+    private static Logger logger = Logger.getLogger("HttpClientUtils");
+
+    private HttpClientUtils() {
+    }
+
+    /**
+     * post xml
+     *
+     * @param url
+     * @param xml
+     * @return
+     */
+    public static String postXml(String url, String xml) throws IOException {
+        HttpClient client = HttpClientBuilder.create().build();
+        client = WebClientDevWrapper.wrapClient(client);
+        HttpPost post = new HttpPost(url);
+        String response = null;
+        InputStream instream = null;
+        try {
+            StringEntity s = new StringEntity(xml, "UTF-8");
+            s.setContentEncoding("UTF-8");
+            s.setContentType("application/xml");
+            post.setEntity(s);
+            HttpResponse res = null;
+            if (client != null) {
+                res = client.execute(post);
+            }
+            if (res != null && res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                HttpEntity entity = res.getEntity();
+                SAXReader reader = new SAXReader();
+                instream = entity.getContent();
+                Document document = reader.read(new InputStreamReader(instream, "utf-8"));
+                response = document.asXML();
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (instream != null) {
+                instream.close();
+            }
+        }
+        return response;
+    }
+
+    /**
+     * post json
+     *
+     * @param url
+     * @param json
+     * @return
+     */
+    public static JSONObject postJson(String url, String json) throws IOException {
+        HttpClient client = HttpClientBuilder.create().build();
+        client = WebClientDevWrapper.wrapClient(client);
+        HttpPost post = new HttpPost(url);
+        JSONObject response = null;
+        InputStream instream = null;
+        try {
+            StringEntity s = new StringEntity(json, "UTF-8");
+            s.setContentEncoding("UTF-8");
+            s.setContentType("application/json");
+            post.setEntity(s);
+            HttpResponse res = null;
+            if (client != null) {
+                res = client.execute(post);
+            }
+            if (res != null && res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                HttpEntity entity = res.getEntity();
+                String charset = "utf-8";
+                instream = entity.getContent();
+                response = new JSONObject(new JSONTokener(new InputStreamReader(instream, charset)));
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (instream != null) {
+                instream.close();
+            }
+        }
+        return response;
+    }
+
+
+    /**
+     * post 键值对
+     *
+     * @param url
+     * @param data 键值对内容
+     * @return
+     */
+    public static String postKeyValue(String url, List<BasicNameValuePair> data) {
+
+
+        CloseableHttpClient httpClient = getHttpClient();
+        try {
+            HttpPost post = new HttpPost(url);
+
+
+            //url格式编码
+            UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(data, "UTF-8");
+            post.setEntity(uefEntity);
+            CloseableHttpResponse httpResponse = httpClient.execute(post);
+            HttpEntity entity = httpResponse.getEntity();
+            try {
+                if (null != entity) {
+                    String result = EntityUtils.toString(entity);
+                    return result;
+                }
+            } finally {
+                httpResponse.close();
+            }
+
+
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        } catch (ClientProtocolException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                closeHttpClient(httpClient);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * get json
+     *
+     * @param url
+     * @return
+     */
+    public static JSONObject get(String url) throws IOException {
+        HttpClient client = HttpClientBuilder.create().build();
+        client = WebClientDevWrapper.wrapClient(client);
+        HttpGet get = new HttpGet(url);
+        JSONObject response = null;
+        InputStream instream = null;
+        try {
+            HttpResponse res = null;
+            if (client != null) {
+                res = client.execute(get);
+            }
+            if (res != null && res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                HttpEntity entity = res.getEntity();
+                instream = entity.getContent();
+                response = new JSONObject(new JSONTokener(new InputStreamReader(instream, "utf-8")));
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (instream != null) {
+                instream.close();
+            }
+        }
+        return response;
+    }
+
+    private static class WebClientDevWrapper {
+        public static HttpClient wrapClient(HttpClient base) {
+            try {
+                RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
+                ConnectionSocketFactory plainSF = new PlainConnectionSocketFactory();
+                registryBuilder.register("http", plainSF);
+                //指定信任密钥存储对象和连接套接字工厂
+                try {
+                    KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+                    SSLContext sslContext = SSLContexts.custom().useTLS().loadTrustMaterial(trustStore, new AnyTrustStrategy()).build();
+                    LayeredConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+                    registryBuilder.register("https", sslSF);
+                } catch (KeyStoreException e) {
+                    throw new RuntimeException(e);
+                } catch (KeyManagementException e) {
+                    throw new RuntimeException(e);
+                } catch (NoSuchAlgorithmException e) {
+                    throw new RuntimeException(e);
+                }
+                Registry<ConnectionSocketFactory> registry = registryBuilder.build();
+                //设置连接管理器
+                PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry);
+                connManager.setDefaultConnectionConfig(ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build());
+                connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(100000).build());
+                //构建客户端
+                return HttpClientBuilder.create().setConnectionManager(connManager).build();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+            return null;
+        }
+
+        private static class AnyTrustStrategy implements TrustStrategy {
+            @Override
+            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+                return true;
+            }
+        }
+
+
+    }
+
+
+    private static CloseableHttpClient getHttpClient() {
+        return HttpClients.createDefault();
+    }
+
+    private static void closeHttpClient(CloseableHttpClient client) throws IOException {
+        if (client != null) {
+            client.close();
+        }
+    }
+
+}

+ 1 - 1
src/main/java/com/shawn/util/JoinpayConstant.java

@@ -41,7 +41,7 @@ public class JoinpayConstant {
      */
     public final static String Notify_Url = "http://app.sunzee.com.cn/api/order/notify.htm";
 
-    public final static String Notify_Url_PromoCode = "http://app.sunzee.com.cn/api/order/promoCodeNotify.htm";
+    public final static String Notify_Url_PromoCode = "https://app.sunzee.com.cn/ShenzeeServer/TPromoCode/promoCodeNotify";
 
     public final static Map<String,String> Result_status = new HashMap<>();
     /**

+ 165 - 46
src/main/java/com/shawn/web/controller/TPromoCodeController.java

@@ -5,9 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.shawn.model.dto.ResultMessage;
 import com.shawn.model.entity.*;
 import com.shawn.model.param.TPromoCodeParam;
-import com.shawn.service.interfac.TAdminServiceInterface;
-import com.shawn.service.interfac.TEquipmentServiceInterface;
-import com.shawn.service.interfac.TPromoCodeServiceInterface;
+import com.shawn.service.interfac.*;
 import com.shawn.util.JoinpayConstant;
 import com.shawn.web.controller.base.BaseController;
 import lombok.extern.apachecommons.CommonsLog;
@@ -18,11 +16,13 @@ import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.net.URLDecoder;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 @CommonsLog
 @RestController
@@ -42,6 +42,10 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
     private TAdminServiceInterface tAdminServiceInterface;
     @Autowired
     private TEquipmentServiceInterface tEquipmentServiceInterface;
+    @Autowired
+    private TProportionServiceInterface tProportionServiceInterface;
+    @Autowired
+    private TOrderServiceInterface tOrderServiceInterface;
     /**
      * 优惠码列表
      * @param
@@ -93,43 +97,44 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
      * @return
      */
     @GetMapping("/buy")
-    public ResponseEntity<?> buy(int number,Long id) {
-        TAdmin admin = tAdminServiceInterface.selectEntityById(id);
+    public ResponseEntity<?> buy(String day,Long adminId,Double pri) {
+        TAdmin admin = tAdminServiceInterface.selectEntityById(adminId);
+        //获取机器
         TEquipmentExample tEquipmentExample = new TEquipmentExample();
         TEquipmentExample.Criteria criteria = tEquipmentExample.createCriteria();
-        criteria.andAdminIdEqualTo(id);
+        criteria.andAdminIdEqualTo(adminId);
         List<TEquipment> equipmentList = tEquipmentServiceInterface.selectByOption(tEquipmentExample);
+
         TEquipment equipment = equipmentList.get(0);
         Long equipmentId = equipment.getId();
-        TProportion proportion = proportionService.getUniqueness(equipment.getAdminId());
-        TProportion.Type type = proportion.getType();
-        Order.Type orderType = null;
+        //获取分销比例
+        TProportionExample tProportionExample = new TProportionExample();
+        TProportionExample.Criteria criteria1 = tProportionExample.createCriteria();
+        criteria1.andAdminIdEqualTo(adminId);
+        List<TProportion> tProportions = tProportionServiceInterface.selectByOption(tProportionExample);
+
+        TProportion proportion = tProportions.get(0);
+        int type = proportion.getType();
+        int orderType = 3;
         Long agencyId = admin.getAgencyId();
         Long merchantId = admin.getMerchantId();
         Long personageId = admin.getPersonageId();
         switch (type) {
-            case agency:
-                orderType = Order.Type.agency;
+            case 1:
+                orderType = 1;
                 break;
-            case merchant:
-                orderType = Order.Type.merchant;
+            case 2:
+                orderType = 2;
                 break;
-            case personage:
-                orderType = Order.Type.personage;
+            case 3:
+                orderType = 3;
                 break;
         }
-        Double money = null;
-        List<Price> prices = priceService.findAll();
-        for(Price price:prices){
-            if(price.getName().equals("优惠码")){
-                money = price.getPrice();
-            }
-        }
 
-        String sn = orderService.initSn(equipmentId);
+        String sn = initSn(equipmentId);
         String orderNo = sn;
         String productName = "优惠码";
-        BigDecimal price = BigDecimal.valueOf(money*number);
+        BigDecimal price = BigDecimal.valueOf(pri);
         BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
         BigDecimal amount = cutPrice;
         String productDesc = "";
@@ -148,10 +153,10 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
         String altUrl = null;
         BigDecimal marketingAmount = null;
 
-//        com.hboxs.entity.Order order = new com.hboxs.entity.Order(sn, product.getId(), productName, price, equipment.getClientId(), equipmentId,
-//                orderType, admin.getId(), agencyId, merchantId, personageId,
-//                frpCode, altInfo.toString(), adminProportion, agencyProportion, merchantProportion, personageProportion, Order.Status.unpay);
-        Order order1 = new Order();
+        String str = String.valueOf(pri);
+        Float pric = Float.parseFloat(str);
+        String frpCode = "WEIXIN_NATIVE";
+        TOrder order1 = new TOrder();
         order1.setSn(sn);
         order1.setType(orderType);
         order1.setAgencyId(agencyId);
@@ -159,17 +164,20 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
         order1.setPersonageId(personageId);
         order1.setAdminId(admin.getId());
         order1.setProductName(productName);
-        order1.setPrice(price);
+        order1.setPrice(pric);
         order1.setEquipmentId(equipmentId);
         order1.setClientId(equipment.getClientId());
-        order1.setStatus(Order.Status.unpay);
-        order1.setFrp_code(frpCode);
-        orderService.create(order1);
+        order1.setStatus(0);
+        order1.setTrxNo(day);
+        order1.setCreateDate(new Date());
+        order1.setModifyDate(new Date());
+        order1.setFrpCode(frpCode);
+        tOrderServiceInterface.insert(order1);
 
         JSONArray altInfo = new JSONArray();
         String result = null;
-        try {
-            result = tradeService.uniPay(
+
+            result = tPromoCodeService.uniPay(
 
                     orderNo, amount, productName, productDesc,
                     commonParameter, returnUrl, notifyUrl, frpCode,
@@ -177,24 +185,135 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
                     buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
             );
 
-        } catch (
-                UnsupportedEncodingException e) {
-            e.printStackTrace();
+
 //            return JsonMessage.error("申请支付失败");
-            return "申请支付失败";
-        }
+//            return ResponseEntity.status(HttpStatus.OK)
+//                    .body(new ResultMessage().setCode(true).setData("申请支付失败").setMessage("SUCCESS"));
+
 
         JSONObject resultJson = JSONObject.parseObject(result);
         // 汇聚支付支付申请返回支付二维码图片
         String rd_Pic = resultJson.getString("rd_Pic");
 
         if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
-            return "找不到支付图片";
+            return ResponseEntity.status(HttpStatus.OK)
+                    .body(new ResultMessage().setCode(true).setData("找不到支付图片").setMessage("SUCCESS"));
+//            return "找不到支付图片";
         }
 //        ModelMap model = new ModelMap();
-        model.addAttribute("image", rd_Pic);
-        model.addAttribute("price", price);
+//        model.addAttribute("image", rd_Pic);
+//        model.addAttribute("price", price);
         return ResponseEntity.status(HttpStatus.OK)
-                .body(new ResultMessage().setCode(true).setData(price).setMessage("SUCCESS"));
+                .body(new ResultMessage().setCode(true).setData(rd_Pic).setMessage("SUCCESS"));
+    }
+
+    private String initSn(Long equipmentId) {
+        StringBuilder number = new StringBuilder();
+        if (equipmentId != null) {
+            Random random = new Random();
+            /**
+             * 6位随机
+             */
+            for (int i = 0; i < 6; i++) {
+                number.append(String.valueOf(random.nextInt(10)));
+            }
+            /**
+             * 设备id
+             */
+            number.append(equipmentId.toString());
+            /**
+             * 日期
+             */
+            number.append(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
+        }
+        return number.toString();
+    }
+
+    /**
+     * 优惠码支付成功回调
+     *
+     * @return
+     */
+    @RequestMapping(value = "/promoCodeNotify", method = RequestMethod.GET)
+    @ResponseBody
+    public Object promoCoderefund(HttpServletRequest request) {
+
+        String r6_Status = request.getParameter("r6_Status");
+
+        // 订单号
+        String sn = request.getParameter("r2_OrderNo");
+        //价格
+        String price = request.getParameter("r3_Amount");
+        Double pri = tPromoCodeService.findPrice();
+        //生成优惠码的个数
+        double num = Double.parseDouble(price)/pri;
+        int number = (int) num;
+
+        TOrderExample tOrderExample = new TOrderExample();
+        TOrderExample.Criteria criteria = tOrderExample.createCriteria();
+        criteria.andSnEqualTo(sn);
+        List<TOrder> tOrders = tOrderServiceInterface.selectByOption(tOrderExample);
+        TOrder order = tOrders.get(0);
+        String day = order.getTrxNo();
+        if(order.getStatus()!=0){
+            return "success";
+        }
+
+        if(JoinpayConstant.r6_Status_100.equals(r6_Status)){
+
+            // 已支付
+            order.setStatus(1);
+
+            // 支付平台产生的流水号
+            String r7_TrxNo = request.getParameter("r7_TrxNo");
+            order.setTrxNo(r7_TrxNo);
+
+            // 格式:YYYY-MM-DD HH:mm:ss
+            String ra_PayTime = request.getParameter("ra_PayTime");
+
+            try {
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
+                order.setPayDate(payDate);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            } catch (UnsupportedEncodingException e) {
+
+                e.printStackTrace();
+            }
+            tOrderServiceInterface.updateById(order);
+            TAdmin admin = tAdminServiceInterface.selectEntityById(order.getAdminId());
+            JSONObject kindData = new JSONObject();
+            kindData.put("sn" , order.getSn());
+            kindData.put("productName" , order.getProductName());
+            List<String> codes =new ArrayList<>();
+            for(int i=0;i<number;i++){
+                String code = initSn(order.getEquipmentId());
+                StringBuffer str = new StringBuffer();
+                str.append(code.substring(0,6));
+                codes.add(str.toString());
+            }
+            Long data = Calendar.getInstance().getTimeInMillis();
+            Long da = Long.valueOf(day);
+            Long month = da*24L*60L*60L*1000L;
+            Long d = data + month;
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String sd = sdf.format(new Date(Long.parseLong(String.valueOf(d))));
+            Date lastUseDate = new Date(Long.parseLong(String.valueOf(d)));
+            for(String code : codes){
+                TPromoCode promoCode = new TPromoCode();
+                promoCode.setCode(Long.parseLong(code));
+                promoCode.setAdminId(String.valueOf(order.getAdminId()));
+                promoCode.setIsUse("0");
+                promoCode.setLastUseDate(lastUseDate);
+                promoCode.setCreateDate(new Date());
+                promoCode.setUserName(admin.getUsername());
+                tPromoCodeService.insert(promoCode);
+            }
+
+            return "支付成功";
+        }
+
+        return "success";
     }
 }