微信应用支付(IOS手机java后端+台)版

  

<强> 0。介绍预览

  

针对需要在IOS手机上接入原生微信支付场景,调用微信进行支付。如图:

  

微信应用支付(IOS手机java后端+台)版”> <img src=

  

<强> 1。资料准备

  

1.1账号注册

  

打开,注册微信开放平台开发者账号

  

1.2开发者认证

  

登录,进入账号中心,进行开发者资质认证。

  

微信应用支付(IOS手机java后端+台)版

  

1.3注册应用

  

认证完成后,进入管理中心,新建移动应用。填写应用资料,其中android版应用签名可通过扫码安装温馨提供的应用获得,详细参考微信文档。创建完成后点击查看,申请开通微信支付。一切准备就绪!

  

微信应用支付(IOS手机java后端+台)版

  

<强> 2. java后台开发

  

添加依赖

        & lt; !——微信支付依赖——比;   & lt; dependency>   & lt; groupId> org.xmlpull   & lt; artifactId> xmlpull   & lt; version> 1.1.3.1 & lt;/version>   & lt;/dependency>   & lt; dependency>   & lt; groupId> net.sf.json-lib   & lt; artifactId> json-lib   & lt; version> 2.3 & lt;/version>   & lt; classifier> jdk15   & lt;/dependency>   & lt; !——https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream——比;   & lt; dependency>   & lt; groupId> com.thoughtworks.xstream   & lt; artifactId> xstream   & lt; version> 1.4.5   & lt;/dependency>   & lt; !——https://mvnrepository.com/artifact/com.ning/async-http-client——比;   & lt; dependency>   & lt; groupId> com.ning   & lt; artifactId> async-http-client   & lt; version> 1.8.13   & lt;/dependency>   
     

生成统一订单

  

        @RequestMapping(值=" https://www.yisu.com/pay/wxpay/params ",产生=癮pplication/json; charset=utf - 8”)   @ResponseBody   公共字符串signprams (HttpServletRequest请求){   字符串res="{代码:404}";   尝试{//充值金额   字符串帐户=request.getParameter(“帐户”);//用户id   字符串sid=request.getParameter (sid);   字符串对象="订单标题”;   字符串的身体="订单描述”;      int acc=(int) (Double.valueOf(账户)* 100);   字符串appid="您的appid”;   字符串out_trade_no="生成您的订单号”;//生成订单数据   String> SortedMap<字符串;payMap=genOrderData(请求、主题的身体,acc, appid out_trade_no);      savePayLog (out_trade_no、帐户、sid、身体payMap.get (“paySign”), nid, 2);//4 .返回数据   res=buildPayRes (payMap out_trade_no);   }捕捉(异常e) {   e.printStackTrace ();   res="{代码:500}”;   }   返回res;   }      私人SortedMap<字符串,String>genOrderData (HttpServletRequest请求,字符串,字符串的身体,   appid int acc,字符串,字符串out_trade_no)   抛出IOException,中InterruptedException, XmlPullParserException {   String> SortedMap<字符串;paraMap=new TreeMap<字符串,String> ();   paraMap。把(“appid”, appid);   paraMap。把(“附加”,主题);   paraMap。把(“身体”,身体);   paraMap。put (" mch_id”、“您的商户id,到商户平台查看”);   paraMap。put (" nonce_str ", create_nonce_str ());   paraMap。把(" notify_url ", " http://pay.xxxxx.com/pay/wxpay/notify.htm ");//此路径是微信服务器调用支付结果通知路径   paraMap。把(“out_trade_no”, out_trade_no);   paraMap。put (" spbill_create_ip ", request.getRemoteAddr ());   paraMap。把(“total_fee”, acc + " ");   paraMap。把(“trade_type”、“应用程序”);   字符串标志=createSign (paraMap);   paraMap。把(“迹象”,签署);//统一下单https://api.mch.weixin.qq.com/pay/unifiedorder   字符串url=" https://api.mch.weixin.qq.com/pay/unifiedorder ";   xml字符串=getRequestXml (paraMap);   字符串xmlStr=HttpKit。帖子(url、xml);//预付商品id   字符串prepay_id=" ";   如果(xmlStr.indexOf(“成功”)!=1){   String> Map

微信应用支付(IOS手机java后端+台)版