精华内容
下载资源
问答
  • 能正常生成prepay_id给客户端,但是客户端支付成功后,微信异步回调接口一直没有接收到数据。网上查了好多原因:1、有说notify_url 地址不对的,不能带参数。这确实是一个注意的地方,但是我的url是OK的。2、有的是...

    用的lumen写的接口,APP支付。

    PHP 7 。微信支付。按照微信官网文档写的。能正常生成prepay_id给客户端,但是客户端支付成功后,微信异步回调接口一直没有接收到数据。网上查了好多原因:

    1、有说notify_url 地址不对的,不能带参数。这确实是一个注意的地方,但是我的url是OK的。

    2、有的是说接口接收微信xml数据时应该用 $xml = file_get_contents('php://input'); 因为PHP7把之前那个$GLOBAL 变量取消了。。。。但是我按照这个写,依然没有接收到数据。

    3、通过查NGINX访问日志,发现微信确实访问了我的回调接口,但是我这边就是接受不到数据。。。。。emmmmm

    4、最后同事。。。用了lumen里Request 里自带的getContent() 方法就能接受到。。。。

    5、看了一下getContent() 的源码

    public function getContent($asResource = false)

    {

    $currentContentIsResource = is_resource($this->content);

    if (\PHP_VERSION_ID < 50600 && false === $this->content) {

    throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');

    }

    if (true === $asResource) {

    if ($currentContentIsResource) {

    rewind($this->content);

    return $this->content;

    }

    // Content passed in parameter (test)

    if (is_string($this->content)) {

    $resource = fopen('php://temp', 'r+');

    fwrite($resource, $this->content);

    rewind($resource);

    return $resource;

    }

    $this->content = false;

    return fopen('php://input', 'rb');

    }

    if ($currentContentIsResource) {

    rewind($this->content);

    return stream_get_contents($this->content);

    }

    if (null === $this->content || false === $this->content) {

    $this->content = file_get_contents('php://input');

    }

    return $this->content;

    }

    估计是走了 return stream_get_contents($this->content);

    但是查了一下 stream_get_contents($this->content);和file_get_contents('php://input'); 没看出什么区别。

    所以知道的大佬方便说一下嘛?

    说是Laravel会拦截所有输入。 如果您使用5.6之前的PHP,php://输入流只能被读取一次。 这意味着你需要从框架中获取数据。 您可以通过访问Request实例上的getContent方法来完成此操作,如下所示:

    $content = Request::getContent(); // Using Request facade

    /* or */

    $content = $request->getContent(); // If you already have a Request instance

    // lying around, from say the controller

    展开全文
  • 1.首先我们先下载微信支付的服务器端demo2.个文件作用介绍index.jsp 下单 payRequest.jsp 获取微信支付prepay_id等。重点我说说这个payNotifyUrl.jsp//---------------------------------------------------------//...

    1.首先我们先下载微信支付的服务器端demo

    c086fad0e43bf30c13e5edddaf09c424

    eeb800617562643e398eb5db9192c6e1

    2.个文件作用介绍

    index.jsp  下单  payRequest.jsp  获取微信支付prepay_id等。

    重点我说说这个payNotifyUrl.jsp

    //---------------------------------------------------------

    //财付通支付通知(后台通知)示例,商户按照此文档进行开发即可

    //---------------------------------------------------------

    //商户号

    String partner = "1900000109";

    //密钥

    String key = "8934e7d15453e97507ef794cf7b0519d";

    //创建支付应答对象

    ResponseHandler resHandler = new ResponseHandler(request, response);

    resHandler.setKey(key);

    //判断签名

    if(resHandler.isTenpaySign()) {

    //通知id

    String notify_id = resHandler.getParameter("notify_id");

    //创建请求对象

    RequestHandler queryReq = new RequestHandler(null, null);

    //通信对象

    TenpayHttpClient httpClient = new TenpayHttpClient();

    //应答对象

    ClientResponseHandler queryRes = new ClientResponseHandler();

    //通过通知ID查询,确保通知来至财付通

    queryReq.init();

    queryReq.setKey(key);

    queryReq.setGateUrl("https://gw.tenpay.com/gateway/verifynotifyid.xml");

    queryReq.setParameter("partner", partner);

    queryReq.setParameter("notify_id", notify_id);

    //通信对象

    httpClient.setTimeOut(5);

    //设置请求内容

    httpClient.setReqContent(queryReq.getRequestURL());

    System.out.println("queryReq:" + queryReq.getRequestURL());

    //后台调用

    if(httpClient.call()) {

    //设置结果参数

    queryRes.setContent(httpClient.getResContent());

    System.out.println("queryRes:" + httpClient.getResContent());

    queryRes.setKey(key);

    //获取返回参数

    String retcode = queryRes.getParameter("retcode");

    String trade_state = queryRes.getParameter("trade_state");

    String trade_mode = queryRes.getParameter("trade_mode");

    //判断签名及结果

    if(queryRes.isTenpaySign()&& "0".equals(retcode) && "0".equals(trade_state) && "1".equals(trade_mode)) {

    System.out.println("订单查询成功");

    //取结果参数做业务处理

    System.out.println("out_trade_no:" + queryRes.getParameter("out_trade_no")+

    " transaction_id:" + queryRes.getParameter("transaction_id"));

    System.out.println("trade_state:" + queryRes.getParameter("trade_state")+

    " total_fee:" + queryRes.getParameter("total_fee"));

    //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee

    System.out.println("discount:" + queryRes.getParameter("discount")+

    " time_end:" + queryRes.getParameter("time_end"));

    //------------------------------

    //处理业务开始

    //------------------------------

    //处理数据库逻辑

    //注意交易单不要重复处理

    //注意判断返回金额

    //------------------------------

    //处理业务完毕

    //------------------------------

    resHandler.sendToCFT("Success");

    }

    else{

    //错误时,返回结果未签名,记录retcode、retmsg看失败详情。

    System.out.println("查询验证签名失败或业务错误");

    System.out.println("retcode:" + queryRes.getParameter("retcode")+

    " retmsg:" + queryRes.getParameter("retmsg"));

    }

    } else {

    System.out.println("后台调用通信失败");

    System.out.println(httpClient.getResponseCode());

    System.out.println(httpClient.getErrInfo());

    //有可能因为网络原因,请求已经处理,但未收到应答。

    }

    }

    else{

    System.out.println("通知签名验证失败");

    }

    %>

    就是上面的这代码。完全没有用。查看sdk源码才知道 这个异步回调是接收微信发送的所有参数,然后排序  加密 验签。  最坑的是  微信 的参数根本不是通过的参数返回的。而是通过的流。所以这个太坑了。下面我把我修改过的源码发出来 帮助大家解决回调问题。

    首先是控制器

    /**

    * 异步回调接口

    * @param request

    * @param response

    * @throws Exception

    */

    @RequestMapping(value="/weixin_parent_notify.do",produces="text/html;charset=utf-8")

    @ResponseBody

    public String WeixinParentNotifyPage(HttpServletRequest request,HttpServletResponse response) throws Exception{

    ServletInputStream instream = request.getInputStream();

    StringBuffer sb = new StringBuffer();

    int len = -1;

    byte[] buffer = new byte[1024];

    while((len = instream.read(buffer)) != -1){

    sb.append(new String(buffer,0,len));

    }

    instream.close();

    SortedMap map = WXRequestUtil.doXMLParseWithSorted(sb.toString());//接受微信的通知参数

    Map return_data = new HashMap();

    //创建支付应答对象

    ResponseHandler resHandler = new ResponseHandler(request, response);

    resHandler.setAllparamenters(map);

    resHandler.setKey(ConstantUtil.PARTNER_KEY[0]);

    //判断签名

    if(resHandler.isTenpaySign()){

    if(!map.get("return_code").toString().equals("SUCCESS")){

    return_data.put("return_code", "FAIL");

    return_data.put("return_msg", "return_code不正确");

    }else{

    if(!map.get("result_code").toString().equals("SUCCESS")){

    return_data.put("return_code", "FAIL");

    return_data.put("return_msg", "result_code不正确");

    }

    String out_trade_no = map.get("out_trade_no").toString();

    String time_end = map.get("time_end").toString();

    BigDecimal total_fee = new BigDecimal(map.get("total_fee").toString());

    //付款完成后,支付宝系统发送该交易状态通知

    System.out.println("交易成功");

    Map order = orderdao.PaymentEndGetOrderInfo(out_trade_no);

    if(order == null){

    System.out.println("订单不存在");

    return_data.put("return_code", "FAIL");

    return_data.put("return_msg", "订单不存在");

    return WXRequestUtil.GetMapToXML(return_data);

    }

    int order_type = (int) order.get("order_type");

    boolean payment_status = (boolean) order.get("payment_status");

    int supplier_id = (int) order.get("supplier_id");

    BigDecimal p = new BigDecimal("100");

    BigDecimal amount = (BigDecimal) order.get("amount");

    amount = amount.multiply(p);

    //如果订单已经支付返回错误

    if(payment_status){

    System.out.println("订单已经支付");

    return_data.put("return_code", "SUCCESS");

    return_data.put("return_msg", "OK");

    return WXRequestUtil.GetMapToXML(return_data);

    }

    //如果支付金额不等于订单金额返回错误

    if(amount.compareTo(total_fee)!=0){

    System.out.println("资金异常");

    return_data.put("return_code", "FAIL");

    return_data.put("return_msg", "金额异常");

    return WXRequestUtil.GetMapToXML(return_data);

    }

    //更新订单信息

    if(orderdao.PaymentEndUpdateOrder(out_trade_no, time_end)){

    System.out.println("更新订单成功");

    //如果该订单是幼儿产品 并且 存在代理

    if(order_type == 2){

    if(supplier_id != 0){

    Map su = userdao.getSupplierInfo(supplier_id);

    String phone = (String) su.get("phone_number");

    String nickname = (String) su.get("nickname");

    String app_token = (String) su.get("app_token");

    String content = "【三盛科创】尊敬的"+ nickname +"您好。您在我们平台出售的商品有新用户下单。请您点击该链接查看发货信息。"+Config.WEB_SERVER+"/order/SupplierOrderInfo.do?order_number="+out_trade_no+"&sid="+app_token+".请您务必妥善包管。";

    MessageUtil.SendMessage(phone,content);

    }

    }else{

    orderdao.UpdateOrderStatus(out_trade_no, 3);//更新订单为已完成

    }

    return_data.put("return_code", "SUCCESS");

    return_data.put("return_msg", "OK");

    return WXRequestUtil.GetMapToXML(return_data);

    }else{

    return_data.put("return_code", "FAIL");

    return_data.put("return_msg", "更新订单失败");

    return WXRequestUtil.GetMapToXML(return_data);

    }

    }

    }else{

    return_data.put("return_code", "FAIL");

    return_data.put("return_msg", "签名错误");

    }

    String xml = WXRequestUtil.GetMapToXML(return_data);

    return xml;

    }

    微信工具类WXRequestUtil.java

    package com.tenpay.util;

    import java.io.BufferedReader;

    import java.io.ByteArrayInputStream;

    import java.io.File;

    import java.io.FileInputStream;

    import java.io.InputStream;

    import java.io.InputStreamReader;

    import java.io.OutputStream;

    import java.net.ConnectException;

    import java.net.HttpURLConnection;

    import java.net.InetAddress;

    import java.net.URL;

    import java.security.KeyStore;

    import java.util.Date;

    import java.util.HashMap;

    import java.util.Iterator;

    import java.util.List;

    import java.util.Map;

    import java.util.SortedMap;

    import java.util.TreeMap;

    import javax.net.ssl.SSLContext;

    import org.apache.http.Consts;

    import org.apache.http.HttpEntity;

    import org.apache.http.client.methods.CloseableHttpResponse;

    import org.apache.http.client.methods.HttpPost;

    import org.apache.http.conn.ssl.SSLConnectionSocketFactory;

    import org.apache.http.conn.ssl.SSLContexts;

    import org.apache.http.entity.StringEntity;

    import org.apache.http.impl.client.CloseableHttpClient;

    import org.apache.http.impl.client.HttpClients;

    import org.apache.http.util.EntityUtils;

    import org.glassfish.jersey.internal.util.Base64;

    import org.jdom.Document;

    import org.jdom.Element;

    import org.jdom.input.SAXBuilder;

    import com.zhiweism.util.MD5;

    import com.zhiweism.util.Util;

    /*

    * 用户发起统一下单请求

    * 作者:董志平

    * 用于发起微信扫码支付接口

    */

    public class WXRequestUtil {

    private static String WXSign = null;

    测试

    public static void main(String[] args) {

    //Map res = SendPayment("苹果","20170106113325",1,0);

    }

    /*

    * 发起支付请求

    * body商品描述

    * out_trade_no订单号

    * total_fee订单金额单位 元

    * product_id商品ID

    */

    public static Map SendPayment(String body,String out_trade_no,double total_fee,int app_type){

    String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

    String xml = WXParamGenerate(body,out_trade_no,total_fee,app_type);

    String res = httpsRequest(url,"POST",xml);

    Map data = null;

    try {

    data = doXMLParse(res);

    } catch (Exception e) {

    data = null;

    }

    return data;

    }

    /**

    * 获取签名

    * @return

    */

    public static String getWXSign() {

    return WXSign;

    }

    /**

    * 获得随机字符串

    *

    */

    public static String NonceStr(){

    String res = Base64.encodeAsString(Math.random()+"::"+new Date().toString()).substring(0, 30);

    return res;

    }

    /**

    * 获取时间戳

    */

    public static String GetTimeStamp(){

    int t = (int)(System.currentTimeMillis()/1000);

    return t+"";

    }

    /**

    * 获取用户的ip

    *

    */

    public static String GetIp() {

    InetAddress ia=null;

    try {

    ia=InetAddress.getLocalHost();

    String localip=ia.getHostAddress();

    return localip;

    } catch (Exception e) {

    return null;

    }

    }

    /**

    * 获取签名

    *

    */

    public static String GetSign(Map param,int app_type){

    String StringA = Util.formatUrlMap(param, false, false);

    String stringSignTemp = MD5.md5(StringA+"&key="+ConstantUtil.PARTNER_KEY[app_type]).toUpperCase();

    return stringSignTemp;

    }

    /**

    *

    * Map转xml数据

    */

    public static String GetMapToXML(Map param){

    StringBuffer sb = new StringBuffer();

    sb.append("");

    for (Map.Entry entry : param.entrySet()) {

    sb.append("");

    sb.append(entry.getValue());

    sb.append(""+ entry.getKey() +">");

    }

    sb.append("");

    return sb.toString();

    }

    //微信统一下单参数设置

    public static String WXParamGenerate(String description,String out_trade_no,double total_fee,int app_type){

    int fee = (int)(total_fee * 100.00);

    Map param = new HashMap();

    param.put("appid", ConstantUtil.APP_ID[app_type]);

    param.put("mch_id", ConstantUtil.PARTNER[app_type]);

    param.put("nonce_str",NonceStr());

    param.put("body",description);

    param.put("out_trade_no",out_trade_no);

    param.put("total_fee", fee+"");

    param.put("spbill_create_ip", GetIp());

    param.put("notify_url", ConstantUtil.WEIXIN_NOTIFY[app_type]);

    param.put("trade_type", "APP");

    WXSign = GetSign(param,app_type);

    param.put("sign", WXSign);

    return GetMapToXML(param);

    }

    //发起微信支付请求

    public static String httpsRequest(String requestUrl, String requestMethod, String outputStr) {

    try {

    URL url = new URL(requestUrl);

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    conn.setDoOutput(true);

    conn.setDoInput(true);

    conn.setUseCaches(false);

    // 设置请求方式(GET/POST)

    conn.setRequestMethod(requestMethod);

    conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");

    // 当outputStr不为null时向输出流写数据

    if (null != outputStr) {

    OutputStream outputStream = conn.getOutputStream();

    // 注意编码格式

    outputStream.write(outputStr.getBytes("UTF-8"));

    outputStream.close();

    }

    // 从输入流读取返回内容

    InputStream inputStream = conn.getInputStream();

    InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");

    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

    String str = null;

    StringBuffer buffer = new StringBuffer();

    while ((str = bufferedReader.readLine()) != null) {

    buffer.append(str);

    }

    // 释放资源

    bufferedReader.close();

    inputStreamReader.close();

    inputStream.close();

    inputStream = null;

    conn.disconnect();

    return buffer.toString();

    } catch (ConnectException ce) {

    System.out.println("连接超时:{}"+ ce);

    } catch (Exception e) {

    System.out.println("https请求异常:{}"+ e);

    }

    return null;

    }

    //退款的请求方法

    public static String httpsRequest2(String requestMethod, String outputStr) throws Exception {

    KeyStore keyStore = KeyStore.getInstance("PKCS12");

    StringBuilder res = new StringBuilder("");

    FileInputStream instream = new FileInputStream(new File("/home/apiclient_cert.p12"));

    try {

    keyStore.load(instream, "".toCharArray());

    } finally {

    instream.close();

    }

    // Trust own CA and all self-signed certs

    SSLContext sslcontext = SSLContexts.custom()

    .loadKeyMaterial(keyStore, "1313329201".toCharArray())

    .build();

    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(

    sslcontext,

    new String[] { "TLSv1" },

    null,

    SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);

    CloseableHttpClient httpclient = HttpClients.custom()

    .setSSLSocketFactory(sslsf)

    .build();

    try {

    HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund");

    httpost.addHeader("Connection", "keep-alive");

    httpost.addHeader("Accept", "*/*");

    httpost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

    httpost.addHeader("Host", "api.mch.weixin.qq.com");

    httpost.addHeader("X-Requested-With", "XMLHttpRequest");

    httpost.addHeader("Cache-Control", "max-age=0");

    httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");

    StringEntity entity2 = new StringEntity(outputStr ,Consts.UTF_8);

    httpost.setEntity(entity2);

    System.out.println("executing request" + httpost.getRequestLine());

    CloseableHttpResponse response = httpclient.execute(httpost);

    try {

    HttpEntity entity = response.getEntity();

    System.out.println("----------------------------------------");

    System.out.println(response.getStatusLine());

    if (entity != null) {

    System.out.println("Response content length: " + entity.getContentLength());

    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));

    String text = "";

    res.append(text);

    while ((text = bufferedReader.readLine()) != null) {

    res.append(text);

    System.out.println(text);

    }

    }

    EntityUtils.consume(entity);

    } finally {

    response.close();

    }

    } finally {

    httpclient.close();

    }

    return res.toString();

    }

    //xml解析

    public static Map doXMLParse(String strxml) throws Exception {

    strxml = strxml.replaceFirst("encoding=\".*\"", "encoding=\"UTF-8\"");

    if(null == strxml || "".equals(strxml)) {

    return null;

    }

    Map m = new HashMap();

    InputStream in = new ByteArrayInputStream(strxml.getBytes("UTF-8"));

    SAXBuilder builder = new SAXBuilder();

    Document doc = builder.build(in);

    Element root = doc.getRootElement();

    List list = root.getChildren();

    Iterator it = list.iterator();

    while(it.hasNext()) {

    Element e = (Element) it.next();

    String k = e.getName();

    String v = "";

    List children = e.getChildren();

    if(children.isEmpty()) {

    v = e.getTextNormalize();

    } else {

    v = getChildrenText(children);

    }

    m.put(k, v);

    }

    //关闭流

    in.close();

    return m;

    }

    //xml解析

    public static SortedMap doXMLParseWithSorted(String strxml) throws Exception {

    strxml = strxml.replaceFirst("encoding=\".*\"", "encoding=\"UTF-8\"");

    if(null == strxml || "".equals(strxml)) {

    return null;

    }

    SortedMap m = new TreeMap();

    InputStream in = new ByteArrayInputStream(strxml.getBytes("UTF-8"));

    SAXBuilder builder = new SAXBuilder();

    Document doc = builder.build(in);

    Element root = doc.getRootElement();

    List list = root.getChildren();

    Iterator it = list.iterator();

    while(it.hasNext()) {

    Element e = (Element) it.next();

    String k = e.getName();

    String v = "";

    List children = e.getChildren();

    if(children.isEmpty()) {

    v = e.getTextNormalize();

    } else {

    v = getChildrenText(children);

    }

    m.put(k, v);

    }

    //关闭流

    in.close();

    return m;

    }

    public static String getChildrenText(List children) {

    StringBuffer sb = new StringBuffer();

    if(!children.isEmpty()) {

    Iterator it = children.iterator();

    while(it.hasNext()) {

    Element e = (Element) it.next();

    String name = e.getName();

    String value = e.getTextNormalize();

    List list = e.getChildren();

    sb.append("");

    if(!list.isEmpty()) {

    sb.append(getChildrenText(list));

    }

    sb.append(value);

    sb.append("" + name + ">");

    }

    }

    return sb.toString();

    }

    }

    修改微信ResponseHandler.java

    package com.tenpay;

    import java.io.IOException;

    import java.io.PrintWriter;

    import java.io.UnsupportedEncodingException;

    import java.util.Iterator;

    import java.util.Map;

    import java.util.Set;

    import java.util.SortedMap;

    import java.util.TreeMap;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import com.tenpay.util.MD5Util;

    import com.tenpay.util.TenpayUtil;

    /**

    *

    * @author miklchen

    *

    */

    public class ResponseHandler {

    private String key;

    private SortedMap parameters;

    private String debugInfo;

    private HttpServletRequest request;

    private HttpServletResponse response;

    private String uriEncoding;

    /**

    *

    * @param request

    * @param response

    */

    public ResponseHandler(HttpServletRequest request,

    HttpServletResponse response) {

    this.request = request;

    this.response = response;

    this.key = "";

    this.parameters = new TreeMap();

    this.debugInfo = "";

    this.uriEncoding = "";

    }

    /**

    */

    public String getKey() {

    return key;

    }

    /**

    *

    */

    public void setKey(String key) {

    this.key = key;

    }

    /**

    * @param parameter

    * @return String

    */

    public String getParameter(String parameter) {

    String s = (String)this.parameters.get(parameter);

    return (null == s) ? "" : s;

    }

    /**

    * @param parameter

    * @param parameterValueֵ

    */

    public void setParameter(String parameter, String parameterValue) {

    String v = "";

    if(null != parameterValue) {

    v = parameterValue.trim();

    }

    this.parameters.put(parameter, v);

    }

    /**

    *

    * @return SortedMap

    */

    public SortedMap getAllParameters() {

    return this.parameters;

    }

    public void setAllparamenters(SortedMap map){

    this.parameters = map;

    }

    /**

    * 微信异步回调签名

    * @return boolean

    */

    public boolean isTenpaySign() {

    StringBuffer sb = new StringBuffer();

    Set es = this.parameters.entrySet();

    Iterator it = es.iterator();

    while(it.hasNext()) {

    Map.Entry entry = (Map.Entry)it.next();

    String k = (String)entry.getKey();

    String v = (String)entry.getValue();

    if(!"sign".equals(k) && null != v && !"".equals(v)) {

    sb.append(k + "=" + v + "&");

    }

    }

    sb.append("key="+this.getKey());

    String enc = TenpayUtil.getCharacterEncoding(this.request, this.response);

    String sign = MD5Util.MD5Encode(sb.toString(), enc).toLowerCase();

    String tenpaySign = this.getParameter("sign").toLowerCase();

    System.out.println("sign:"+sign+" tenpaysign:"+tenpaySign);

    return tenpaySign.equals(sign);

    }

    /**

    *

    * @throws IOException

    */

    public void sendToCFT(String msg) throws IOException {

    String strHtml = msg;

    PrintWriter out = this.getHttpServletResponse().getWriter();

    out.println(strHtml);

    out.flush();

    out.close();

    }

    /**

    *

    * @return String

    */

    public String getUriEncoding() {

    return uriEncoding;

    }

    /**

    * @param uriEncoding

    * @throws UnsupportedEncodingException

    */

    public void setUriEncoding(String uriEncoding)

    throws UnsupportedEncodingException {

    if (!"".equals(uriEncoding.trim())) {

    this.uriEncoding = uriEncoding;

    String enc = TenpayUtil.getCharacterEncoding(request, response);

    Iterator it = this.parameters.keySet().iterator();

    while (it.hasNext()) {

    String k = (String) it.next();

    String v = this.getParameter(k);

    v = new String(v.getBytes(uriEncoding.trim()), enc);

    this.setParameter(k, v);

    }

    }

    }

    /**

    */

    public String getDebugInfo() {

    return debugInfo;

    }

    /**

    *

    */

    protected void setDebugInfo(String debugInfo) {

    this.debugInfo = debugInfo;

    }

    protected HttpServletRequest getHttpServletRequest() {

    return this.request;

    }

    protected HttpServletResponse getHttpServletResponse() {

    return this.response;

    }

    }

    试试是不是已经可以发起异步回调了。记得key  在  微信支付 -》API安全  下面设置。

    标签:

    展开全文
  • 微信支付异步回调 flask如何接收 微信支付中,异步回调中,请求的数据类型’CONTENT_TYPE’: ‘text/xml’,我们想要提取里面的数据,需要下面的方法 from flask import request from lxml import etree data = {...

    微信支付异步回调 flask如何接收

    • 微信支付中,异步回调中,请求的数据类型’CONTENT_TYPE’: ‘text/xml’,我们想要提取里面的数据,需要下面的方法
    from flask import request
    from lxml import etree
    
    data = {}
        root = etree.fromstring(request.data, parser=etree.XMLParser(resolve_entities=False))
        for child in root:
            data[child.tag] = child.text
    print(data)        
    
    展开全文
  • java 微信支付异步回调接口

    千次阅读 2019-07-08 10:51:22
    1.微信支付异步回调接口 @SuppressWarnings("static-access") @RequestMapping("callback") @ResponseBody public Object callback(HttpServletRequest request,HttpServletResponse response) throws Exception...

    1.微信支付异步回调接口

    @SuppressWarnings("static-access")
        @RequestMapping("callback")
        @ResponseBody
        public Object callback(HttpServletRequest request,HttpServletResponse response) throws Exception{
            ResultBean result = new ResultBean();
            String inputLine="";
            String notityXml = "";
            try {
                while ((inputLine = request.getReader().readLine()) != null) {
                    notityXml += inputLine;
                }
                request.getReader().close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("异步回调XML信息:"+notityXml);
            if(!notityXml.isEmpty()){
                //解析并读取统一下单中的参数信息
                Map<String, Object> prepayMap = XmlUtil.getPrepayMapInfo(notityXml);
                if(!prepayMap.isEmpty()){
                    String orderId = prepayMap.get("out_trade_no")+"";
                    String resCode=prepayMap.get("result_code")+"";
                    String returnCode=prepayMap.get("return_code")+"";
                    System.out.println("解析并读取统一下单中的参数信息:"+orderId+"==="+resCode+"==="+returnCode);
                    }
                    //回调中业务逻辑完毕
                }else{
                    result.fillCode(ResultBeanCodeEnum.OPERA_FAIL);
                }
            }else{
                result.fillCode(ResultBeanCodeEnum.OPERA_FAIL);
            }
            return result;
        }

    2.解析并读取统一下单中的参数信息工具类

     //解析xml
        public static  Map<String, Object> getPrepayMapInfo(String Str)  {
            //解析并读取统一下单中的参数信息
            //1.去掉前后的xml标签
            String notityXml = Str.replaceAll("</?xml>", "");
            System.out.println(notityXml);
            //2.匹配一段一段这样的数据   <attach><![CDATA[支付测试]]></attach>
            Pattern pattern = Pattern.compile("<.*?/.*?>");
            Matcher matcher = pattern.matcher(notityXml);
            //3.配置是否包含<![CDATA[CNY]]> CDATA 包裹的数据
            Pattern pattern2 = Pattern.compile("!.*]");
            Map<String, Object> mapInfo = new HashMap<>();
            while(matcher.find()) {
                //获取键
                String key = matcher.group().replaceAll(".*/", "");
                key = key.substring(0, key.length() - 1);
                Matcher matcher2 = pattern2.matcher(matcher.group());
                String value = matcher.group().replaceAll("</?.*?>", "");
                //获取值
                if(matcher2.find() && !value.equals("DATA")) {
                    value = matcher2.group().replaceAll("!.*\\[", "");
                    value = value.substring(0, value.length() - 2);
                } 
                mapInfo.put(key, value);
            }
            return mapInfo;
        }

    展开全文
  • 1.微信支付异步回调接口@SuppressWarnings("static-access")@RequestMapping("callback")@ResponseBodypublic Object callback(HttpServletRequest request,HttpServletResponse response) throws Exception{...
  • 如题:微信支付异步回调地址只能设置一个。但是在实际开发中,一个公司往往有好几个项目需要微信支付相关的业务,不同的项目有不同的域名解析。 多申请几个微信公众号显然过于浪费,且不利于财务的统一管理。 方法...
  • 最近公司在开发微信支付和支付宝支付,前期的工作都已经做好了,但是在异步回调取值的时候,异步回调一直在调用,弄得我数据一直重复的存入数据库,真觉得大姨妈来了,根本停不下来!哈哈,还是不要开车了,看到问题...
  • 1.首先我们先下载微信支付的服务器端demo 2.个文件作用介绍 index.jsp 下单 payRequest.jsp 获取微信支付prepay_id等。 重点我说说这个payNotifyUrl.jsp &lt;%@ page language="java" contentType...
  • 1、收取微信异步回调参数 //获取返回的xml格式数据 $payXml = file_get_contents("php://input"); //将xml格式转化为json格式 $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_...
  • 之前在接触的项目中,微信支付回调函数都是使用以下变量获取POST数据:前提:php配置中,必须启用 always_populate_raw_post_data//php.ini 配置always_populate_raw_post_data = On//适用于...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 878
精华内容 351
关键字:

微信支付异步回调