package org.jeecg.modules.pay.serverPay;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/anonymous")
@Slf4j
public class TelAnonymousController
{
    
//    @Autowired
//    private WxPayService wxPayService;
//
//    //发起支付
//    @PostMapping("/wx/order/create")
//    public WxUnifiedOrderVo createOrder(){
//        //发起V3 服务商发起支付
//        EcommerceServiceImpl ecommerceService=new EcommerceServiceImpl(wxPayService);
//     // 1. 创建请求对象
//        PartnerTransactionsRequest orderRequest=new PartnerTransactionsRequest();
//        // 2. 根据订单系统传过来的订单信息组装支付参数，创建支付订单
//        //服务商应用ID
//        orderRequest.setSpAppid(wxPayProperties.getAppId());
//        //服务商户号
//        orderRequest.setSpMchid(wxPayProperties.getMchId());
//        //子商户号
//        orderRequest.setSubMchid(dealerMerchant.getMchid());
//        //子商户/二级商户应用ID
//        orderRequest.setSubAppid(wxPayProperties.getSubAppId());
//        //商品描述
//        orderRequest.setDescription("商品描述");
//        //商户订单号
//        orderRequest.setOutTradeNo("订单id");
//        //设置交易结束时间为24小时
//        orderRequest.setTimeExpire(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(new Date()));
//        //通知地址
//        orderRequest.setNotifyUrl(wxPayProperties.getNotifyUrl());
//        //订单金额
//        PartnerTransactionsRequest.Amount amount = new PartnerTransactionsRequest.Amount();
//        amount.setTotal(BaseWxPayRequest.yuanToFen("订单金额"));
//        orderRequest.setAmount(amount);
//        //支付者
//        PartnerTransactionsRequest.Payer payer = new PartnerTransactionsRequest.Payer();
//        payer.setSubOpenid("支付者的openid");
//        orderRequest.setPayer(payer);
//        //发起下单请求
//        TransactionsResult partner = ecommerceService.partner(TradeTypeEnum.JSAPI, partnerTransactionsRequest);
//        //生成签名
//        WxUnifiedOrderVo tokenJSAPI = WechatSignUtil.getTokenJSAPI(wxPayProperties.getSubAppId(), partner.getPrepayId(), wxPayProperties.getPrivateKeyPath());
//        tokenJSAPI.setOrderId(order.getId());
//        return tokenJSAPI;
//    }
//
//		//支付回调
//	@ApiOperation(value = "支付回调通知处理")
//    @PostMapping("/wx/notify/order")
//    public void parseOrderNotifyResult(@RequestBody String resultData) throws WxPayException {
//        log.info("回调：{}",resultData);
//        EcommerceServiceImpl ecommerceService = new EcommerceServiceImpl(wxPayService);
//        PartnerTransactionsNotifyResult notifyResult = ecommerceService.parsePartnerNotifyResult(resultData, null);
//        //此处解析到了回调信息
//        log.info("回调：{}",notifyResult.getResult());
//      //业务逻辑
//    }
//
//    		//支付回调
//	@ApiOperation(value = "主动查询支付信息")
//    @PostMapping("/wx/order/select")
//    public void wxSelectOrderStatus() throws WxPayException {
//        //构建ecommerceService
//        EcommerceServiceImpl ecommerceService = new EcommerceServiceImpl(wxPayService);
//        //构建PartnerTransactionsQueryRequest对象
//        PartnerTransactionsQueryRequest queryRequest = new PartnerTransactionsQueryRequest();
//        queryRequest.setOutTradeNo("订单ID");
//        queryRequest.setSpMchid("服务商ID");
//        queryRequest.setSubMchid("特约商户ID");
//        PartnerTransactionsResult partnerTransactionsResult=new PartnerTransactionsResult();
//        try {
//            //普通查询订单API
//            partnerTransactionsResult = ecommerceService.queryPartnerTransactions(queryRequest);
//        } catch (WxPayException e) {
//            e.printStackTrace();
//        }
//    }
}
