APP微信提现接口

昨天分享了微信支付接口、今天早上正好有空、给大家分享一下APP提现的接口、

提现必须得用双向证书、所以大家一定要在微信的商户平台找到相应的地方去设置、因为我做这个提现已经有一段时间了、所以设置微信商户平台的那几个地方没有图的情况、也说不清楚、下次再做提现的时候、给大家分享如何设置商户平台那几个地方、不是很难、下面贴代码

<?php
namespace Home\Controller;
use Think\Controller;
class TixianController extends Controller{

   //高级功能-》开发者模式-》获取
   private $app_id1 = '';      //appid
   private $app_secret1 = ''; //secreat
   private $apikey1 = '';  //支付秘钥
   private $mchid1 = 's';        //商户号
   
        private $app_id=null;
       private $app_secret=null;
       private $apikey=null;
       private $mchid=null;
      
      
   public  $error=0;
   public $state = '';
   //金额,需在实例化时传入
   public $amount = '0';
   //用户订单号,需在实例化时传入
   public $order_sn = '';
   //用户openid,需在实例化时传入
   public $openid = '';
   
   

   //微信提现操作接口-------   public function actionAct_tixian()
   {
      
      $this->state=md5(uniqid(rand(), TRUE));
      $this->amount=I('amount');//设置POST过来钱数
      $this->order_sn=rand(100,999).date('YmdHis');  //随机数可以作为单号
      $this->openid= I('openid');  //设置获取POST过来用户的OPENID
        $user_id = I('user_id');

      $this->app_id=$this->app_id1;
      $this->app_secret=$this->app_secret1;
      $this->apikey=$this->apikey1;
      $this->mchid=$this->mchid1;
      $xml=$this->tiXianAction();
      $result=simplexml_load_string($xml);
      
      if($result->return_code=='SUCCESS' && 
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个简单的ThinkPHP 5.1版本的微信提现代码示例: ```php <?php namespace app\index\controller; use think\Controller; use think\facade\Config; use think\facade\Log; use think\facade\Request; class Withdraw extends Controller { // 微信提现接口 public function wechatWithdraw() { // 获取请求参数 $params = Request::param(); // 获取微信支付配置信息 $wxPayConfig = Config::get('wxpay'); // 请求参数构造 $data = [ 'mch_appid' => $wxPayConfig['appid'], 'mchid' => $wxPayConfig['mchid'], 'nonce_str' => md5(uniqid()), 'partner_trade_no' => $params['order_no'], 'openid' => $params['openid'], 'check_name' => 'NO_CHECK', // 不校验真实姓名 'amount' => $params['amount'], // 提现金额,单位分 'desc' => '提现描述', 'spbill_create_ip' => $_SERVER['REMOTE_ADDR'], ]; // 生成签名 $data['sign'] = $this->makeSign($data, $wxPayConfig['key']); // 数组转xml格式 $xmlData = $this->arrayToXml($data); // 发送请求 $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; $response = $this->postXmlCurl($xmlData, $url, true, 6, $wxPayConfig['sslcert_path'], $wxPayConfig['sslkey_path']); // 解析返回的xml数据 $result = $this->xmlToArray($response); // 返回结果 if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { // 提现成功 return json(['code' => 0, 'msg' => '提现成功']); } else { // 提现失败 Log::error('微信提现失败:' . $response); return json(['code' => 1, 'msg' => '提现失败,请重试']); } } // 生成签名 private function makeSign($data, $key) { // 去除数组中的空值 $data = array_filter($data); // 按照键名的字典序排序 ksort($data); // 生成字符串 $stringA = ''; foreach ($data as $key => $value) { $stringA .= $key . '=' . $value . '&'; } $stringA .= 'key=' . $key; // 进行MD5签名并转化为大写 return strtoupper(md5($stringA)); } // 数组转xml格式 private function arrayToXml($data) { $xml = "<xml>"; foreach ($data as $key => $value) { if (is_numeric($value)) { $xml .= "<" . $key . ">" . $value . "</" . $key . ">"; } else { $xml .= "<" . $key . "><![CDATA[" . $value . "]]></" . $key . ">"; } } $xml .= "</xml>"; return $xml; } // 发送post请求xml数据 private function postXmlCurl($xmlData, $url, $useCert = false, $timeout = 30, $sslcert_path = '', $sslkey_path = '') { $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData); if ($useCert == true) { curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM'); curl_setopt($ch, CURLOPT_SSLCERT, $sslcert_path); curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM'); curl_setopt($ch, CURLOPT_SSLKEY, $sslkey_path); } $data = curl_exec($ch); curl_close($ch); return $data; } // xml转数组 private function xmlToArray($xml) { // 禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlString = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $result = json_decode(json_encode($xmlString), true); return $result; } } ``` 其中,$wxPayConfig是微信支付的配置信息,可以在config目录下的wxpay.php文件中进行配置。 该示例仅供参考,实际使用时需要根据自己的业务需求进行相应的修改和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值