zoukankan      html  css  js  c++  java
  • 微信支付退款流程 php

    // 设置时区 

    date_default_timezone_set("Asia/Shanghai");

    // 配置

    $ref = strtoupper(md5("appid=$appid&mch_id=$mch_id&nonce_str=$nonce_str&op_user_id=$user_id"
    . "&out_refund_no=$out_refund_no&out_trade_no=$transaction_id&refund_fee=$refund_fee&total_fee=$total_fee"
    . "&key=$key")); //sign加密MD5
    $refund = ['appid' => $appid, //应用ID,固定
    'mch_id' => $mch_id, //商户号,固定
    'nonce_str' => $nonce_str, //随机字符串
    'op_user_id' => $user_id, //操作员
    'out_refund_no' => $out_refund_no, //商户内部唯一退款单号
    'out_trade_no' => $transaction_id, //商户订单号,pay_sn码 1.1二选一,微信生成的订单号,在支付通知中有返回
    //'transaction_id'=>$transaction_id,//微信订单号 1.2二选一,商户侧传给微信的订单号
    'refund_fee' => $refund_fee, //退款金额
    'total_fee' => $total_fee, //总金额
    'sign' => $ref//签名
    ];
    微信签名认证工具 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=20_1
    $url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
    ; //微信退款地址,post请求
    $xml = arrayToXml($refund);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); //证书检查
    // 设置证书
    curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'pem');
    curl_setopt($ch, CURLOPT_SSLCERT, $_SERVER['DOCUMENT_ROOT'] . '/plugins/payment/weixin/cert/apiclient_cert.pem');
    curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'pem');
    curl_setopt($ch, CURLOPT_SSLKEY, $_SERVER['DOCUMENT_ROOT'] . '/plugins/payment/weixin/cert/apiclient_key.pem');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    $xml = curl_exec($ch);
    // 返回结果0的时候能只能表明程序是正常返回不一定说明退款成功而已
    if ($xml) {
    curl_close($ch);
    // 把xml转化成数组
    libxml_disable_entity_loader(true);
    $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
    // var_dump($xmlstring);
    $result['errNum'] = 0;
    $result['info'] = (array)($xmlstring);
    return $result;
    } else {
    $error = curl_errno($ch);
    curl_close($ch);
    // 错误的时候返回错误码。
    $result['errNum'] = $error;
    return $result;
    }
     
  • 相关阅读:
    google protobuf
    spawn-fcgi和libfcgi源码解读
    [Linux] 查看进程的上下文切换pidstat
    [MySQL] update语句的redo log过程
    [转载] PHP 8新特性之JIT简介
    [PHP] 新浪企邮webmail在memcache实践使用共享session
    [Go] Golang练习项目-web客服系统即时通讯websocket项目go-fly
    [PHP] php8的jit不支持32位系统WARNING: JIT not supported by host architecture
    [PHP] 源码编译安装opcache
    [PHP] 查找使用的哪个配置文件php.ini
  • 原文地址:https://www.cnblogs.com/yjhsm/p/13345088.html
Copyright © 2011-2022 走看看