suochencheng 7 rokov pred
rodič
commit
2bf8285a08

+ 5 - 0
src/main/java/com/izouma/awesomeadmin/datasource/DynamicDataSource.java

@@ -3,6 +3,7 @@ package com.izouma.awesomeadmin.datasource;
 import com.izouma.awesomeadmin.model.DataSourceInfo;
 import com.izouma.awesomeadmin.model.DataSourceInfo;
 import com.izouma.awesomeadmin.util.Const;
 import com.izouma.awesomeadmin.util.Const;
 import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
 import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
 
 
 import javax.sql.DataSource;
 import javax.sql.DataSource;
@@ -18,6 +19,10 @@ public class DynamicDataSource extends AbstractRoutingDataSource {
     protected DataSource determineTargetDataSource() {
     protected DataSource determineTargetDataSource() {
         // 根据数据库选择方案,拿到要访问的数据库
         // 根据数据库选择方案,拿到要访问的数据库
         String dataSourceName = determineCurrentLookupKey();
         String dataSourceName = determineCurrentLookupKey();
+
+        if (StringUtils.isEmpty(dataSourceName)) {
+            dataSourceName = "dataSource";
+        }
         if (!dataSourceName.equals("dataSource")) {
         if (!dataSourceName.equals("dataSource")) {
             DataSource datasource = (DataSource) targetDataSource.get(DynamicDataSourceHolder.getDataSource());
             DataSource datasource = (DataSource) targetDataSource.get(DynamicDataSourceHolder.getDataSource());
             if (datasource == null) {
             if (datasource == null) {

+ 2 - 0
src/main/java/com/izouma/weixin/dao/WxpayTempMapper.java

@@ -20,6 +20,8 @@ public interface WxpayTempMapper{
 
 
     int updateByPrimaryKeySelective(WxpayTemp record);
     int updateByPrimaryKeySelective(WxpayTemp record);
 
 
+    int updateByOutTradeNo(WxpayTemp record);
+
     List<WxpayTemp> queryAllWxpayTemp(WxpayTemp record);
     List<WxpayTemp> queryAllWxpayTemp(WxpayTemp record);
 
 
     List<WxpayTemp> queryWxpayTempByPage(Map<String, Object> parameter);
     List<WxpayTemp> queryWxpayTempByPage(Map<String, Object> parameter);

+ 76 - 0
src/main/java/com/izouma/weixin/dao/WxpayTempMapper.xml

@@ -20,6 +20,7 @@
         <result column="point" property="point" jdbcType="DECIMAL"/>
         <result column="point" property="point" jdbcType="DECIMAL"/>
         <result column="cash" property="cash" jdbcType="DECIMAL"/>
         <result column="cash" property="cash" jdbcType="DECIMAL"/>
         <result column="open_id" property="openId" jdbcType="VARCHAR"/>
         <result column="open_id" property="openId" jdbcType="VARCHAR"/>
+        <result column="result_code" property="resultCode" jdbcType="VARCHAR"/>
     </resultMap>
     </resultMap>
     <sql id="Base_Column_List">
     <sql id="Base_Column_List">
         <trim suffixOverrides=",">
         <trim suffixOverrides=",">
@@ -59,6 +60,8 @@
 
 
             open_id,
             open_id,
 
 
+            result_code,
+
         </trim>
         </trim>
     </sql>
     </sql>
     <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
     <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
@@ -129,6 +132,9 @@
             <if test="openId!= null">
             <if test="openId!= null">
                 open_id,
                 open_id,
             </if>
             </if>
+            <if test="resultCode!= null">
+                result_code,
+            </if>
         </trim>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">
             <if test="id != null">
@@ -185,6 +191,9 @@
             <if test="openId != null">
             <if test="openId != null">
                 #{openId,jdbcType=VARCHAR},
                 #{openId,jdbcType=VARCHAR},
             </if>
             </if>
+            <if test="resultCode != null">
+                #{resultCode,jdbcType=VARCHAR},
+            </if>
         </trim>
         </trim>
     </insert>
     </insert>
     <update id="updateByPrimaryKeySelective" parameterType="com.izouma.weixin.model.WxpayTemp">
     <update id="updateByPrimaryKeySelective" parameterType="com.izouma.weixin.model.WxpayTemp">
@@ -244,9 +253,65 @@
             <if test="openId != null">
             <if test="openId != null">
                 open_id= #{openId,jdbcType=VARCHAR},
                 open_id= #{openId,jdbcType=VARCHAR},
             </if>
             </if>
+            <if test="resultCode != null">
+                result_code= #{resultCode,jdbcType=VARCHAR},
+            </if>
         </set>
         </set>
         where id = #{id,jdbcType=INTEGER}
         where id = #{id,jdbcType=INTEGER}
     </update>
     </update>
+    <update id="updateByOutTradeNo" parameterType="com.izouma.weixin.model.WxpayTemp">
+        update wxpay_temp
+        <set>
+            <if test="orderId != null">
+                order_id= #{orderId,jdbcType=VARCHAR},
+            </if>
+            <if test="userId != null">
+                user_id= #{userId,jdbcType=VARCHAR},
+            </if>
+            <if test="totalAmount != null">
+                total_amount= #{totalAmount,jdbcType=DECIMAL},
+            </if>
+            <if test="outTradeNo != null">
+                out_trade_no= #{outTradeNo,jdbcType=VARCHAR},
+            </if>
+            <if test="transactionId != null">
+                transaction_id= #{transactionId,jdbcType=VARCHAR},
+            </if>
+            <if test="typeFlag != null">
+                type_flag= #{typeFlag,jdbcType=INTEGER},
+            </if>
+            <if test="outRefundNo != null">
+                out_refund_no= #{outRefundNo,jdbcType=VARCHAR},
+            </if>
+            <if test="refundAmount != null">
+                refund_amount= #{refundAmount,jdbcType=DECIMAL},
+            </if>
+            <if test="coin != null">
+                coin= #{coin,jdbcType=DECIMAL},
+            </if>
+            <if test="point != null">
+                point= #{point,jdbcType=DECIMAL},
+            </if>
+            <if test="cash != null">
+                cash= #{cash,jdbcType=DECIMAL},
+            </if>
+            <if test="openId != null">
+                open_id= #{openId,jdbcType=VARCHAR},
+            </if>
+            <if test="resultCode != null">
+                result_code= #{resultCode,jdbcType=VARCHAR},
+            </if>
+        </set>
+        where
+        out_trade_no = #{outTradeNo}
+        <if test="orderId != null and !&quot;&quot;.equals(orderId)">
+            and order_id = #{orderId}
+        </if>
+        <if test="userId != null and !&quot;&quot;.equals(userId)">
+            and user_id = #{userId}
+        </if>
+
+    </update>
     <select id="queryWxpayTempByPage" parameterType="java.util.Map" resultType="com.izouma.weixin.model.WxpayTemp">
     <select id="queryWxpayTempByPage" parameterType="java.util.Map" resultType="com.izouma.weixin.model.WxpayTemp">
         select
         select
         <include refid="Base_Column_List"/>
         <include refid="Base_Column_List"/>
@@ -307,6 +372,9 @@
             <if test="record.openId != null and !&quot;&quot;.equals(record.openId)">
             <if test="record.openId != null and !&quot;&quot;.equals(record.openId)">
                 and open_id = #{record.openId}
                 and open_id = #{record.openId}
             </if>
             </if>
+            <if test="record.resultCode != null and !&quot;&quot;.equals(record.resultCode)">
+                and result_code = #{record.resultCode}
+            </if>
             <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
             <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
                     OR order_id LIKE concat('%',#{record.searchKey},'%')
                     OR order_id LIKE concat('%',#{record.searchKey},'%')
@@ -436,6 +504,9 @@
             <if test="openId != null and !&quot;&quot;.equals(openId)">
             <if test="openId != null and !&quot;&quot;.equals(openId)">
                 and open_id = #{openId}
                 and open_id = #{openId}
             </if>
             </if>
+            <if test="resultCode != null and !&quot;&quot;.equals(resultCode)">
+                and result_code = #{resultCode}
+            </if>
             <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
             <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
                     OR order_id LIKE concat('%',#{searchKey},'%')
                     OR order_id LIKE concat('%',#{searchKey},'%')
@@ -565,6 +636,11 @@
                 and open_id = #{openId}
                 and open_id = #{openId}
             </if>
             </if>
 
 
+            <if test="resultCode != null and !&quot;&quot;.equals(resultCode)">
+                and result_code = #{resultCode}
+            </if>
+
+
         </where>
         </where>
         LIMIT 1
         LIMIT 1
     </select>
     </select>

+ 94 - 64
src/main/java/com/izouma/weixin/model/WxpayTemp.java

@@ -2,13 +2,14 @@ package com.izouma.weixin.model;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.*;
+
 import com.fasterxml.jackson.annotation.JsonAutoDetect;
 import com.fasterxml.jackson.annotation.JsonAutoDetect;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonInclude;
 
 
 
 
 @JsonAutoDetect
 @JsonAutoDetect
 @JsonInclude(JsonInclude.Include.NON_NULL)
 @JsonInclude(JsonInclude.Include.NON_NULL)
-public class WxpayTemp{
+public class WxpayTemp {
     private Integer id;
     private Integer id;
     private String delFlag;
     private String delFlag;
     private Date updateTime;
     private Date updateTime;
@@ -28,168 +29,197 @@ public class WxpayTemp{
     private BigDecimal cash;
     private BigDecimal cash;
     private String openId;
     private String openId;
 
 
-private String searchKey;
+    /**
+     * SUCCESS/FAIL/WAIT_BUYER_PAY
+     */
+    private String resultCode;
+
+    private String searchKey;
 
 
-/**
-* and,test_name,like,value;or,remark,=,123
-*/
-private String advancedQuery;
+    /**
+     * and,test_name,like,value;or,remark,=,123
+     */
+    private String advancedQuery;
 
 
-/**
-* column_name_,desc_;column_name_,asc
-*/
-private String orderByStr;
+    /**
+     * column_name_,desc_;column_name_,asc
+     */
+    private String orderByStr;
 
 
-    public Integer getId(){
+    public Integer getId() {
         return this.id;
         return this.id;
     }
     }
 
 
-    public void setId(Integer id){
+    public void setId(Integer id) {
         this.id = id;
         this.id = id;
     }
     }
-    public String getDelFlag(){
+
+    public String getDelFlag() {
         return this.delFlag;
         return this.delFlag;
     }
     }
 
 
-    public void setDelFlag(String delFlag){
+    public void setDelFlag(String delFlag) {
         this.delFlag = delFlag;
         this.delFlag = delFlag;
     }
     }
-    public Date getUpdateTime(){
+
+    public Date getUpdateTime() {
         return this.updateTime;
         return this.updateTime;
     }
     }
 
 
-    public void setUpdateTime(Date updateTime){
+    public void setUpdateTime(Date updateTime) {
         this.updateTime = updateTime;
         this.updateTime = updateTime;
     }
     }
-    public String getUpdateUser(){
+
+    public String getUpdateUser() {
         return this.updateUser;
         return this.updateUser;
     }
     }
 
 
-    public void setUpdateUser(String updateUser){
+    public void setUpdateUser(String updateUser) {
         this.updateUser = updateUser;
         this.updateUser = updateUser;
     }
     }
-    public Date getCreateTime(){
+
+    public Date getCreateTime() {
         return this.createTime;
         return this.createTime;
     }
     }
 
 
-    public void setCreateTime(Date createTime){
+    public void setCreateTime(Date createTime) {
         this.createTime = createTime;
         this.createTime = createTime;
     }
     }
-    public String getCreateUser(){
+
+    public String getCreateUser() {
         return this.createUser;
         return this.createUser;
     }
     }
 
 
-    public void setCreateUser(String createUser){
+    public void setCreateUser(String createUser) {
         this.createUser = createUser;
         this.createUser = createUser;
     }
     }
-    public String getOrderId(){
+
+    public String getOrderId() {
         return this.orderId;
         return this.orderId;
     }
     }
 
 
-    public void setOrderId(String orderId){
+    public void setOrderId(String orderId) {
         this.orderId = orderId;
         this.orderId = orderId;
     }
     }
-    public String getUserId(){
+
+    public String getUserId() {
         return this.userId;
         return this.userId;
     }
     }
 
 
-    public void setUserId(String userId){
+    public void setUserId(String userId) {
         this.userId = userId;
         this.userId = userId;
     }
     }
-    public BigDecimal getTotalAmount(){
+
+    public BigDecimal getTotalAmount() {
         return this.totalAmount;
         return this.totalAmount;
     }
     }
 
 
-    public void setTotalAmount(BigDecimal totalAmount){
+    public void setTotalAmount(BigDecimal totalAmount) {
         this.totalAmount = totalAmount;
         this.totalAmount = totalAmount;
     }
     }
-    public String getOutTradeNo(){
+
+    public String getOutTradeNo() {
         return this.outTradeNo;
         return this.outTradeNo;
     }
     }
 
 
-    public void setOutTradeNo(String outTradeNo){
+    public void setOutTradeNo(String outTradeNo) {
         this.outTradeNo = outTradeNo;
         this.outTradeNo = outTradeNo;
     }
     }
-    public String getTransactionId(){
+
+    public String getTransactionId() {
         return this.transactionId;
         return this.transactionId;
     }
     }
 
 
-    public void setTransactionId(String transactionId){
+    public void setTransactionId(String transactionId) {
         this.transactionId = transactionId;
         this.transactionId = transactionId;
     }
     }
-    public Integer getTypeFlag(){
+
+    public Integer getTypeFlag() {
         return this.typeFlag;
         return this.typeFlag;
     }
     }
 
 
-    public void setTypeFlag(Integer typeFlag){
+    public void setTypeFlag(Integer typeFlag) {
         this.typeFlag = typeFlag;
         this.typeFlag = typeFlag;
     }
     }
-    public String getOutRefundNo(){
+
+    public String getOutRefundNo() {
         return this.outRefundNo;
         return this.outRefundNo;
     }
     }
 
 
-    public void setOutRefundNo(String outRefundNo){
+    public void setOutRefundNo(String outRefundNo) {
         this.outRefundNo = outRefundNo;
         this.outRefundNo = outRefundNo;
     }
     }
-    public BigDecimal getRefundAmount(){
+
+    public BigDecimal getRefundAmount() {
         return this.refundAmount;
         return this.refundAmount;
     }
     }
 
 
-    public void setRefundAmount(BigDecimal refundAmount){
+    public void setRefundAmount(BigDecimal refundAmount) {
         this.refundAmount = refundAmount;
         this.refundAmount = refundAmount;
     }
     }
-    public BigDecimal getCoin(){
+
+    public BigDecimal getCoin() {
         return this.coin;
         return this.coin;
     }
     }
 
 
-    public void setCoin(BigDecimal coin){
+    public void setCoin(BigDecimal coin) {
         this.coin = coin;
         this.coin = coin;
     }
     }
-    public BigDecimal getPoint(){
+
+    public BigDecimal getPoint() {
         return this.point;
         return this.point;
     }
     }
 
 
-    public void setPoint(BigDecimal point){
+    public void setPoint(BigDecimal point) {
         this.point = point;
         this.point = point;
     }
     }
-    public BigDecimal getCash(){
+
+    public BigDecimal getCash() {
         return this.cash;
         return this.cash;
     }
     }
 
 
-    public void setCash(BigDecimal cash){
+    public void setCash(BigDecimal cash) {
         this.cash = cash;
         this.cash = cash;
     }
     }
-    public String getOpenId(){
+
+    public String getOpenId() {
         return this.openId;
         return this.openId;
     }
     }
 
 
-    public void setOpenId(String openId){
+    public void setOpenId(String openId) {
         this.openId = openId;
         this.openId = openId;
     }
     }
 
 
-public String getSearchKey() {
-    return searchKey;
-}
+    public String getSearchKey() {
+        return searchKey;
+    }
 
 
-public void setSearchKey(String searchKey) {
-    this.searchKey = searchKey;
-}
+    public void setSearchKey(String searchKey) {
+        this.searchKey = searchKey;
+    }
 
 
-public String getAdvancedQuery() {
-    return advancedQuery;
-}
+    public String getAdvancedQuery() {
+        return advancedQuery;
+    }
 
 
-public void setAdvancedQuery(String advancedQuery) {
-    this.advancedQuery = advancedQuery;
-}
+    public void setAdvancedQuery(String advancedQuery) {
+        this.advancedQuery = advancedQuery;
+    }
 
 
-public String getOrderByStr() {
-    return orderByStr;
-}
+    public String getOrderByStr() {
+        return orderByStr;
+    }
 
 
-public void setOrderByStr(String orderByStr) {
-    this.orderByStr = orderByStr;
-}
+    public void setOrderByStr(String orderByStr) {
+        this.orderByStr = orderByStr;
+    }
+
+    public String getResultCode() {
+        return resultCode;
+    }
 
 
+    public void setResultCode(String resultCode) {
+        this.resultCode = resultCode;
+    }
 }
 }
 
 

+ 50 - 121
src/main/java/com/izouma/weixin/web/WeiXinController.java

@@ -2,8 +2,10 @@ package com.izouma.weixin.web;
 
 
 import com.izouma.awesomeadmin.constant.AppConstant;
 import com.izouma.awesomeadmin.constant.AppConstant;
 import com.izouma.awesomeadmin.model.MemberCoin;
 import com.izouma.awesomeadmin.model.MemberCoin;
+import com.izouma.awesomeadmin.model.ProductInfo;
 import com.izouma.awesomeadmin.model.UserInfo;
 import com.izouma.awesomeadmin.model.UserInfo;
 import com.izouma.awesomeadmin.service.MemberCoinService;
 import com.izouma.awesomeadmin.service.MemberCoinService;
+import com.izouma.awesomeadmin.service.ProductInfoService;
 import com.izouma.awesomeadmin.service.UserInfoService;
 import com.izouma.awesomeadmin.service.UserInfoService;
 import com.izouma.awesomeadmin.shiro.WechatToken;
 import com.izouma.awesomeadmin.shiro.WechatToken;
 import com.izouma.awesomeadmin.util.Base64;
 import com.izouma.awesomeadmin.util.Base64;
@@ -56,6 +58,9 @@ public class WeiXinController {
     @Autowired
     @Autowired
     private WxpayTempMapper wxpayTempMapper;
     private WxpayTempMapper wxpayTempMapper;
 
 
+    @Autowired
+    private ProductInfoService productInfoService;
+
     @RequestMapping(value = "/auth", method = RequestMethod.GET)
     @RequestMapping(value = "/auth", method = RequestMethod.GET)
     @ResponseBody
     @ResponseBody
     public ModelAndView auth(@RequestParam("redirectUri") String redirectUri) {
     public ModelAndView auth(@RequestParam("redirectUri") String redirectUri) {
@@ -115,153 +120,67 @@ public class WeiXinController {
                 JSONObject attachJson = new JSONObject(attach);
                 JSONObject attachJson = new JSONObject(attach);
 
 
                 WxpayTemp wxpayTemp = new WxpayTemp();
                 WxpayTemp wxpayTemp = new WxpayTemp();
-                wxpayTemp.setOrderId(attachJson.getString("orderId"));
-                wxpayTemp.setCoin(BigDecimal.valueOf(attachJson.getDouble("coin")));
-                wxpayTemp.setPoint(BigDecimal.valueOf(attachJson.getDouble("point")));
+                wxpayTemp.setUserId(attachJson.getString("userId"));
+                wxpayTemp.setOrderId(attachJson.getString("productId"));
                 wxpayTemp.setCash(BigDecimal.valueOf(attachJson.getDouble("cash")));
                 wxpayTemp.setCash(BigDecimal.valueOf(attachJson.getDouble("cash")));
                 wxpayTemp.setTotalAmount(BigDecimal.valueOf(attachJson.getInt("total") / 100.0));
                 wxpayTemp.setTotalAmount(BigDecimal.valueOf(attachJson.getInt("total") / 100.0));
                 wxpayTemp.setOutTradeNo(m.get("out_trade_no"));
                 wxpayTemp.setOutTradeNo(m.get("out_trade_no"));
                 wxpayTemp.setTransactionId(m.get("transaction_id"));
                 wxpayTemp.setTransactionId(m.get("transaction_id"));
-                wxpayTemp.setTypeFlag(AppConstant.Aliapi.BUY);
-
-                wxpayTempMapper.insertSelective(wxpayTemp);
-
-                //TODO 订单回调
-            }
-        } catch (Exception e) {
-            logger.error("微信支付回调异常", e);
-        }
-
-
-        return null;
-    }
-
-
-    @RequestMapping(value = "/notifyRecharge", method = RequestMethod.POST)
-    @ResponseBody
-    public ModelAndView notifyRecharge(HttpServletRequest request, HttpServletResponse response) {
-
-        try {
-
-            Map<String, String> m = notifyMap(request, response);
-            if (m != null && "SUCCESS".equals(m.get("result_code"))) {
-                String attach = m.get("attach");
-                JSONObject attachJson = new JSONObject(attach);
 
 
-                Integer userId = attachJson.getInt("userId");
-                Integer money = attachJson.getInt("money") / 100;
+                wxpayTempMapper.updateByOutTradeNo(wxpayTemp);
 
 
-                UserInfo userInfo = userInfoService.getUserInfoById(userId + "");
+                logger.info("buyProductInfo");
+                try {
+                    ProductInfo productInfo = productInfoService.getProductInfoById(attachJson.getString("productId"));
+                    if (productInfo != null) {
+                        if (AppConstant.ProductType.RECHARGE == productInfo.getTypeFlag()) {//如果是充值类型
 
 
+                            MemberCoin memberCoin = new MemberCoin();
+                            memberCoin.setMoney(productInfo.getCoin());
+                            memberCoin.setUserId(Integer.valueOf(attachJson.getString("userId")));
+                            memberCoin.setRemark("购买" + productInfo.getProductName() + "套餐,充值");
+                            memberCoin.setRechargeType(AppConstant.RechargeType.WEI_XIN);
 
 
-                /**
-                 * 余额
-                 */
-                double moneyCoin = userInfo.getMoneyCoin();
-                UserInfo updateUser = new UserInfo();
-                updateUser.setId(userId);
-                updateUser.setMoneyCoin(moneyCoin + money);
-                userInfoService.updateUserInfo(updateUser);
+                            memberCoinService.recharge(memberCoin);
 
 
 
 
-                MemberCoin memberCoin = new MemberCoin();
-                memberCoin.setCreateUser("微信充值");
-                memberCoin.setUserId(userId);
-                memberCoin.setMoney(BigDecimal.valueOf(money));
-                memberCoin.setBalance(BigDecimal.valueOf(moneyCoin + money));
-                memberCoin.setTypeFlag(AppConstant.CoinType.RECHARGE);
-                memberCoin.setRemark("微信充值," + money);
-                memberCoinService.createMemberCoin(memberCoin);
+                        } else {
+                            //TODO 购买VIP
+                        }
 
 
+                    }
 
 
-                WxpayTemp wxpayTemp = new WxpayTemp();
+                } catch (Exception e) {
+                    logger.error("buyProductInfo", e);
+                }
 
 
-                wxpayTemp.setUserId(String.valueOf(userId));
-                wxpayTemp.setOutTradeNo(m.get("out_trade_no"));
-                wxpayTemp.setTransactionId(m.get("transaction_id"));
-                wxpayTemp.setTotalAmount(BigDecimal.valueOf(money));
-                wxpayTemp.setTypeFlag(AppConstant.Aliapi.RECHARGE);
 
 
-                wxpayTempMapper.insertSelective(wxpayTemp);
             }
             }
-
         } catch (Exception e) {
         } catch (Exception e) {
-            logger.error("微信充值回调异常", e);
+            logger.error("微信支付回调异常", e);
         }
         }
 
 
+
         return null;
         return null;
     }
     }
 
 
 
 
-    @RequestMapping(value = "/recharge", method = RequestMethod.POST)
+    @RequestMapping(value = "/unifiedOrder", method = RequestMethod.GET)
     @ResponseBody
     @ResponseBody
-    public Map recharge(@RequestParam(required = true, value = "userId") Integer userId, @RequestParam(required = true, value = "money") Integer money) {
-        Map<String, String> result = new HashMap<String, String>();
-
+    public Map<String, String> unifiedOrder(@RequestParam(required = true, value = "userId") String userId,
+                                            @RequestParam(required = true, value = "productId") String productId
+    ) {
+        Map<String, String> result = new HashMap<>();
         try {
         try {
 
 
             MyConfig config = new MyConfig();
             MyConfig config = new MyConfig();
 
 
-            int total = money;
-
-            //测试为一分
-            //total = 1;
-
-            JSONObject attach = new JSONObject();
-            attach.put("userId", userId);
-            attach.put("money", money);
-
-            WxPaySendData data = new WxPaySendData();
-            data.setDevice_info(AppConstant.DEVICE_INFO);
-            data.setBody("充值");
-            data.setOut_trade_no(WeixinUtil.create_out_trade_no());
-            data.setNotify_url(PropertiesFileLoader.getProperties("weixin_notify_url_recharge"));
-            data.setTotal_fee(total);
-            data.setTrade_type(AppConstant.TRADE_TYPE_APP);
-            //data.setSpbill_create_ip("117.62.182.63");
-            data.setSpbill_create_ip(WeixinUtil.getHostAdderss());
-            //扫码支付不需要openId
-            //data.setOpenid(openId);
-
-            data.setAttach(attach.toString());
-
-            Map<String, String> unified = WeixinUtil.unifiedOrder(data);
-
-            String timeStamp = MbappUtil.create_timestamp();
-            String nonceStr = MbappUtil.create_nonce_str();
-            String packageStr = "prepay_id=" + unified.get("prepay_id");
-            //生成sign签名
-            Map<String, String> params = new HashMap<>();
-
-            params.put("appId", config.getAppID());
-            params.put("timeStamp", timeStamp);
-            params.put("nonceStr", nonceStr);
-            params.put("package", packageStr);
-
-            result.put("appId", config.getAppID());
-            result.put("timeStamp", timeStamp);
-            result.put("nonceStr", nonceStr);
-            result.put("myPackage", packageStr);
-            result.put("paySign", WXPayUtil.generateSignature(params, config.getKey()));
-
-            result.put("prepay_id", unified.get("prepay_id"));
-            result.put("code_url", unified.get("code_url"));
-        } catch (Exception e) {
-            logger.error("", e);
-        }
-        return result;
-    }
+            double cash = 1;
 
 
-    @RequestMapping(value = "/unifiedOrder", method = RequestMethod.GET)
-    @ResponseBody
-    public Map<String, String> unifiedOrder(@RequestParam(required = true, value = "orderId") String orderId, @RequestParam(required = true, value = "coin") double coin,
-                                            @RequestParam(required = true, value = "point") double point) {
-        Map<String, String> result = new HashMap<>();
-        try {
+            ProductInfo productInfo = productInfoService.getProductInfoById(productId);
 
 
-            MyConfig config = new MyConfig();
+            cash = productInfo.getMoney().doubleValue();
 
 
-            double cash = 1;//userOrderService.calculatedPrice(orderId, coin, point);
             int total = 0;
             int total = 0;
 
 
 
 
@@ -271,15 +190,14 @@ public class WeiXinController {
             //total = 1;
             //total = 1;
 
 
             JSONObject attach = new JSONObject();
             JSONObject attach = new JSONObject();
-            attach.put("orderId", orderId);
-            attach.put("coin", coin);
-            attach.put("point", point);
+            attach.put("productId", productId);
+            attach.put("userId", userId);
             attach.put("cash", cash);
             attach.put("cash", cash);
             attach.put("total", total);
             attach.put("total", total);
 
 
             WxPaySendData data = new WxPaySendData();
             WxPaySendData data = new WxPaySendData();
             data.setDevice_info(AppConstant.DEVICE_INFO);
             data.setDevice_info(AppConstant.DEVICE_INFO);
-            data.setBody("商品");
+            data.setBody(productInfo.getProductName());
             data.setOut_trade_no(MbappUtil.create_out_trade_no());
             data.setOut_trade_no(MbappUtil.create_out_trade_no());
             data.setNotify_url(PropertiesFileLoader.getProperties("weixin_notify_url"));
             data.setNotify_url(PropertiesFileLoader.getProperties("weixin_notify_url"));
             data.setTotal_fee(total);
             data.setTotal_fee(total);
@@ -310,6 +228,17 @@ public class WeiXinController {
 
 
             result.put("prepay_id", unified.get("prepay_id"));
             result.put("prepay_id", unified.get("prepay_id"));
             result.put("code_url", unified.get("code_url"));
             result.put("code_url", unified.get("code_url"));
+
+
+            WxpayTemp wxpayTemp = new WxpayTemp();
+            wxpayTemp.setOrderId(productId);
+            wxpayTemp.setCash(BigDecimal.valueOf(cash));
+            wxpayTemp.setTotalAmount(BigDecimal.valueOf(total / 100.0));
+            wxpayTemp.setOutTradeNo(data.getOut_trade_no());
+            wxpayTemp.setTypeFlag(AppConstant.Aliapi.BUY);
+            wxpayTemp.setResultCode("WAIT_BUYER_PAY");
+            wxpayTempMapper.insertSelective(wxpayTemp);
+
         } catch (Exception e) {
         } catch (Exception e) {
             logger.error("", e);
             logger.error("", e);
         }
         }

+ 3 - 3
src/main/resources/spring/appDataSource.xml

@@ -79,9 +79,9 @@
         <!-- 配置MyBatis全局配置文件:mybatis-config.xml -->
         <!-- 配置MyBatis全局配置文件:mybatis-config.xml -->
         <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
         <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
         <!-- 扫描entity包 使用别名 -->
         <!-- 扫描entity包 使用别名 -->
-        <property name="typeAliasesPackage" value="com.izouma.awesomeadmin.model"/>
+        <property name="typeAliasesPackage" value="com.izouma.awesomeadmin.model,com.izouma.weixin.model"/>
         <!-- 扫描sql配置文件:mapper需要的xml文件 -->
         <!-- 扫描sql配置文件:mapper需要的xml文件 -->
-        <property name="mapperLocations" value="classpath:com/izouma/awesomeadmin/dao/*Mapper.xml"/>
+        <property name="mapperLocations" value="classpath:com/izouma/awesomeadmin/dao/*Mapper.xml,com/izouma/weixin/dao/*Mapper.xml"/>
     </bean>
     </bean>
 
 
 
 
@@ -90,7 +90,7 @@
         <!-- 注入sqlSessionFactory -->
         <!-- 注入sqlSessionFactory -->
         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
         <!-- 给出需要扫描dao接口包 -->
         <!-- 给出需要扫描dao接口包 -->
-        <property name="basePackage" value="com.izouma.awesomeadmin.dao"/>
+        <property name="basePackage" value="com.izouma.awesomeadmin.dao,com.izouma.weixin.dao"/>
 
 
     </bean>
     </bean>
 
 

+ 1 - 0
src/main/resources/spring/appWebService.xml

@@ -13,6 +13,7 @@
 
 
 	<!-- 扫描service包下所有使用注解的类型 -->
 	<!-- 扫描service包下所有使用注解的类型 -->
 	<context:component-scan base-package="com.izouma.awesomeadmin.service" />
 	<context:component-scan base-package="com.izouma.awesomeadmin.service" />
+	<context:component-scan base-package="com.izouma.weixin.service" />
 
 
 	<!-- 配置事务管理器 -->
 	<!-- 配置事务管理器 -->
 	<bean id="transactionManager"
 	<bean id="transactionManager"

+ 1 - 0
src/main/resources/spring/spring-mvc.xml

@@ -42,6 +42,7 @@
 
 
     <!-- 4:扫描web相关的bean -->
     <!-- 4:扫描web相关的bean -->
     <context:component-scan base-package="com.izouma.awesomeadmin.web"/>
     <context:component-scan base-package="com.izouma.awesomeadmin.web"/>
+    <context:component-scan base-package="com.izouma.weixin.web"/>
 
 
 
 
     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">