자바 의 상품 구 매 과정 강의day19(9)

3923 단어 Java
전단 코드 호출 조회 방법 은 pinyogou - cat - web 프로젝트 를 참조 합 니 다.[AppleScript] 일반 텍스트 보기?1queryPayStatus(response.out_trade_no);//결제 상태 조회
주문 시간 초과 처리
/**
  *          
  * @param userId 
  * @param orderId 
  */
 public void deleteOrderFromRedis(String userId,Long orderId);

(2)   pinyougou-seckill-service   SeckillOrderServiceImpl.java 

@Override 
 public void deleteOrderFromRedis(String userId, Long orderId) {
  //     ID      
  TbSeckillOrder seckillOrder = (TbSeckillOrder)
redisTemplate.boundHashOps("seckillOrder").get(userId); 
  if(seckillOrder!=null &&
 seckillOrder.getId().longValue()== orderId.longValue() ){
    redisTemplate.boundHashOps("seckillOrder").delete(userId);//     
    
    //     
   //1.             
    TbSeckillGoods 
seckillGoods=(TbSeckillGoods)redisTemplate.boundHashOps("seckillGoods").get(seckill
Order.getSeckillId()); 
    if(seckillGoods!=null){
     seckillGoods.setStockCount(seckillGoods.getStockCount()+1);  
redisTemplate.boundHashOps("seckillGoods").put(seckillOrder.getSeckillId(),
seckillGoods);//     
 }    
  } 
 }

       
(1)   pinyougou-pay-interface   WeixinPayService    

/**
  *      
  * @param out_trade_no 
  * @return
  */
 public Map closePay(String out_trade_no);

(2)   pinyougou-pay-service   WeixinPayServiceImpl 

@Override 
 public Map closePay(String out_trade_no) {
  Map param=new HashMap(); 
  param.put("appid", appid);//     ID 
  param.put("mch_id", partner);//    
  param.put("out_trade_no", out_trade_no);//    
  param.put("nonce_str", WXPayUtil.generateNonceStr());//      
  String url="https://api.mch.weixin.qq.com/pay/closeorder"; 
  try {
   String xmlParam = WXPayUtil.generateSignedXml(param, partnerkey); 
HttpClient client=new HttpClient(url); 
   client.setHttps(true); 
   client.setXmlParam(xmlParam); 
   client.post(); 
   String result = client.getContent(); 
   Map map = WXPayUtil.xmlToMap(result); 
   System.out.println(map); 
   return map; 
  } catch (Exception e) {
   e.printStackTrace(); 
   return null; 
  }  
 }

3        
   pinyougou-seckill-web   PayController.java 

/**
  *        
  * @param out_trade_no 
  * @return
  */
 @RequestMapping("/queryPayStatus")
 public Result queryPayStatus(String out_trade_no){
//         
  String 
userId=SecurityContextHolder.getContext().getAuthentication().getName(); 
  Result result=null;   
  int x=0;   
  while(true){
   ........ 
   try {
    Thread.sleep(3000);//     
   } catch (InterruptedException e) {
    e.printStackTrace(); 
   } 
   //              ,             ,      1    
   x++; 
   if(x>20){    
    result=new  Result(false, "     ");  
    //1.           (    ) 
    Map payresult =
weixinPayService.closePay(out_trade_no);     
    if( !"SUCCESS".equals(payresult.get("result_code")) ){//      
      
     if("ORDERPAID".equals(payresult.get("err_code"))){
      result=new Result(true, "    ");  
      seckillOrderService.saveOrderFromRedisToDb(userId,
Long.valueOf(out_trade_no), map.get("transaction_id")); 
}     
    }    
    if(result.isSuccess()==false){
     System.out.println("  ,    "); 
     //2.     
     seckillOrderService.deleteOrderFromRedis(userId,
Long.valueOf(out_trade_no));  
    }    
    break; 
   }   
  }
  return result; 
 }

     
pinyougou-seckill-web   payController.js 

//        
 queryPayStatus=function(out_trade_no){
  payService.queryPayStatus(out_trade_no).success(
   function(response){
    if(response.success){
     location.href="paysuccess.html#?money="+$scope.money; 
    }else{     
     if(response.message=='     '){
 location.href="payTimeOut.html";  
     }else{
      location.href="payfail.html"; 
     }        
    }    
   }
  ); 
 }

좋은 웹페이지 즐겨찾기