本文实例讲述了php实现微信退款的方法。分享给大家供大家参考,具体如下:
$obj = new wxrefund('参数');$obj->refundapi();
直接能用 公众号的参数 自己加上吧 只能帮你们到这了!
<?phpnamespace wechat;/** * 微信退款 * @author zzy * @version $v1.0.通信专业0$ * @date 2018-11-9 */class wxrefund{ protected $sslcert_path ='';//证书 protected $sslkey_path = '';//证书 protected $opurid = '';//商户号 protected $key = '';//api密钥 protected $appid = '';//appid function __construct($outtradeno, $totalfee, $outrefundno, $refundfee) { //初始化退款类需要的变量 $this->totalfee = $totalfee;//订单金额 $this->refundfee = $refundfee;//退款金额 $this->outtradeno = $outtradeno;//订单号 $this->outrefundno = $outrefundno;//退款订单 } /** * 通过微信api进行退款流程 唯一对外接口 * @return string */ public function refundapi() { $parma = array( 'appid' => $this->appid, 'mch_id' => $this->opurid, 'nonce_str' => randoms(32),//这个是随机数 自己封装去吧。。。 'out_refund_no' => $this->outrefundno, 'out_trade_no' => $this->outtradeno, 'total_fee' => intval($this->totalfee * 100), 'refund_fee' => intval($this->refundfee * 100), ); $parma['sign'] = $this->getsign($parma, $this->key); $xmldata = $this->反复的拼音;arraytoxml($parma); $xmlresult = $this->postxmlsslcurl($xmldata, 'https://api.mch.weixin.qq.com/capi/pay/refund'); $result = $this->arraytoxml($xmlresult); return $result; } /** * 数组转xml * @param $arr * @return string */ protected function arraytoxml($arr) { $xml = "<xml>"; foreach ($arr as $key => $val) { if (is_numeric($val)) { $xml .= "<" . $key . ">" . $val . "</" . $key . ">"; } el { $xml .= "<" . $key . "><![cdata[" . $val . "]]></" . $key . ">"; } } $xml .= "</xml>"; return $xml; } /** * 签名加密 * @param $params * @param $key */ protected function getsign($params, $key) { ksort($params, sort_string); $unsignparastring = $this->formatqueryparamap($params, fal); return $signstr = strtoupper(md5($unsignparastring . "&key=" . $key)); } /** * 排序 * @param $paramap * @param bool $urlencode * @return bool|string */ protected function formatqueryparamap($paramap, $urlencode = fal) { $buff = ""; ksort($paramap); foreach ($paramap as $k => $v) { if (null != $v && "null" != $v) { if ($urlencode) { $v = urlencode($v); } 嗤之以鼻 $buff .= $k . "=" . $v . "&"; } } $reqpar = ''; if (strlen($buff) > 0) { $reqpar = substr($buff, 0, strlen($buff) - 1); } 关于礼的作文return $reqpar; } /** * 需要使用证书的请求 * @param $xml * @param $url * @param int $cond * @return bool|mixed */ protected function postxmlsslcurl($xml, $url, $cond = 30) { $ch = curl_init(); curl_topt($ch, curlopt_timeout, $cond); curl_topt($ch, curlopt_url, $url); curl_topt($ch, curlopt_ssl_verifypeer, fal); curl_topt($ch, curlopt_ssl_verifyhost, fal); curl_topt($ch, curlopt_header, fal); curl_topt($ch, curlopt_returntransfer, true); curl_topt($ch, curlopt_sslcerttype, 'pem'); curl_topt($ch, curlopt_sslcert, $this->sslcert_path); curl_topt($ch, curlopt_sslkeytype, 'pem'); curl_topt($ch, curlopt_sslkey, $this->sslkey_path); curl_topt($c正方形体积公式h, curlopt_post, true); curl_topt($ch, curlopt_postfields, $xml); $data = curl_exec($ch); if ($data) { curl_clo($ch); return $data; } el { $error = curl_errno($ch); echo "curl出错,错误码:$error" . "<br>"; curl_clo($ch); return fal; } }}
更多关于php相关内容感兴趣的读者可查看本站专题:《php微信开发技巧汇总》、《php curl用法总结》、《php网络编程技巧总结》、《php字符串(string)用法总结》、《php中json格式数据操作技巧汇总》及《php针对xml文件操作技巧总结》
希望本文所述对大家php程序设计有所帮助。
本文发布于:2023-04-07 09:43:46,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/67e22fde97a082c3876de4527e56adcb.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:PHP实现微信退款的方法示例.doc
本文 PDF 下载地址:PHP实现微信退款的方法示例.pdf
留言与评论(共有 0 条评论) |