濮阳杆衣贸易有限公司

主頁 > 知識庫 > PHP APP微信提現(xiàn)接口代碼

PHP APP微信提現(xiàn)接口代碼

熱門標(biāo)簽:電信外呼系統(tǒng)多少錢一個(gè)月 桂陽公司如何做地圖標(biāo)注 神龍斗士電話機(jī)器人 代理打電話機(jī)器人 宿州正規(guī)外呼系統(tǒng)軟件 合肥企業(yè)外呼系統(tǒng)線路 萍鄉(xiāng)商鋪地圖標(biāo)注 太原400電話申請流程 企業(yè)400電話辦理多少費(fèi)用

本文實(shí)例為大家分享了APP微信提現(xiàn)接口的具體代碼,供大家參考,具體內(nèi)容如下

之前分享了微信支付接口、現(xiàn)在給大家分享一下APP提現(xiàn)的接口。

提現(xiàn)必須得用雙向證書、所以大家一定要在微信的商戶平臺找到相應(yīng)的地方去設(shè)置、因?yàn)槲易鲞@個(gè)提現(xiàn)已經(jīng)有一段時(shí)間了、所以設(shè)置微信商戶平臺的那幾個(gè)地方?jīng)]有圖的情況、也說不清楚、下次再做提現(xiàn)的時(shí)候、給大家分享如何設(shè)置商戶平臺那幾個(gè)地方、不是很難、下面貼代碼

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

  //高級功能-》開發(fā)者模式-》獲取
  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 = '';
  //金額,需在實(shí)例化時(shí)傳入
  public $amount = '0';
  //用戶訂單號,需在實(shí)例化時(shí)傳入
  public $order_sn = '';
  //用戶openid,需在實(shí)例化時(shí)傳入
  public $openid = '';
  
  

  //微信提現(xiàn)操作接口-------》
  public function actionAct_tixian()
  {
   
   $this->state=md5(uniqid(rand(), TRUE));
   $this->amount=I('amount');//設(shè)置POST過來錢數(shù)
   $this->order_sn=rand(100,999).date('YmdHis'); //隨機(jī)數(shù)可以作為單號
   $this->openid= I('openid'); //設(shè)置獲取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'  $result->result_code=='SUCCESS') {

        $cash = D('cash');
        $data['user_id'] = $user_id;
        $data['amount'] = $this->amount;
        $res = $cash->where('user_id="'.$user_id.'"')->find();
        if($res){
          $res2 = $cash->where('user_id="'.$user_id.'"')->setInc('amount',$this->amount);
          $res4 = D('member')->where('user_id="'.$user_id.'"')->setDec('user_balance',$this->amount);
        }else{
          $res3 = $cash->add($data);
        }

      $output = array('code' => 1, 'data' => $result->result_code, 'info' => '提現(xiàn)成功');
      exit(json_encode($output));
   }else{

      $output = array('code' => 2, 'data' => $xml, 'info' => '提現(xiàn)失敗');
      exit(json_encode($output));
   }
  }
  /**
  * 提現(xiàn)接口操作,控制器調(diào)用
  * @param $openid 用戶openid 唯一標(biāo)示
  * @return
  */
  //提現(xiàn)接口操作
  public function tiXianAction(){
   //獲取xml數(shù)據(jù)
   $data=$this->getdataXml($this->openid);
   $ch = curl_init ();
   //接口地址
   $MENU_URL="https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";

   curl_setopt ( $ch, CURLOPT_URL, $MENU_URL );
   curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
   curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
   curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );

   //證書地址,微信支付下面

    curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
    curl_setopt($ch,CURLOPT_SSLCERT, 'C:\web\www\Home\wx_pay\apiclient_cert.pem'); //證書這塊大家把文件放到哪都行、
    curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
    curl_setopt($ch,CURLOPT_SSLKEY, 'C:\web\www\Home\wx_pay\apiclient_key.pem');//注意證書名字千萬別寫錯(cuò)、

   //$zs1=dirname(dirname(__FILE__)).'\wx_pay\apiclient_cert.pem';
   //$zs2=dirname(dirname(__FILE__)).'\wx_pay\apiclient_key.pem';
   //show_bug($zs1);

   //curl_setopt($ch,CURLOPT_SSLCERT,$zs1);
   //curl_setopt($ch,CURLOPT_SSLKEY,$zs2);
   // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01;
   // Windows NT 5.0)');
   //curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
   curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
   curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
   curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
   $info = curl_exec ( $ch );
    //返回結(jié)果
    if($info){
      curl_close($ch);
      return $info;
    } else {
      $error = curl_errno($ch);
      curl_close($ch);
      return "curl出錯(cuò),錯(cuò)誤碼:$error";
    }
  }
  /**
  * 獲取數(shù)據(jù)封裝為數(shù)組
  * @param $openid 用戶openid 唯一標(biāo)示
  * @return xml
  */

  private function getdataXml($openid){
   //封裝成數(shù)據(jù)
   $dataArr=array(
     'amount'=>$this->amount*100,//金額(以分為單位,必須大于100)
     'check_name'=>'NO_CHECK',//校驗(yàn)用戶姓名選項(xiàng),NO_CHECK:不校驗(yàn)真實(shí)姓名 FORCE_CHECK:強(qiáng)校驗(yàn)真實(shí)姓名(未實(shí)名認(rèn)證的用戶會校驗(yàn)失敗,無法轉(zhuǎn)賬)OPTION_CHECK:針對已實(shí)名認(rèn)證的用戶才校驗(yàn)真實(shí)姓名(未實(shí)名認(rèn)證用戶不校驗(yàn),可以轉(zhuǎn)賬成功)
     'desc'=>'提現(xiàn)',//描述
     'mch_appid'=>$this->app_id,
     'mchid'=>$this->mchid,//商戶號
     'nonce_str'=>rand(100000, 999999),//不長于32位的隨機(jī)數(shù)
     'openid'=>$openid,//用戶唯一標(biāo)識
     'partner_trade_no'=>$this->order_sn,//商戶訂單號
     're_user_name'=>'',//用戶姓名,check_name為NO_CHECK時(shí)為可選項(xiàng)
     'spbill_create_ip'=>$_SERVER["REMOTE_ADDR"],//服務(wù)器ip
   );
   //獲取簽名
   $sign=$this->getSign($dataArr);
   //xml數(shù)據(jù)
   $data="xml>
     mch_appid>".$dataArr['mch_appid']."/mch_appid>
     mchid>".$dataArr['mchid']."/mchid>
     nonce_str>".$dataArr['nonce_str']."/nonce_str>
     partner_trade_no>".$dataArr['partner_trade_no']."/partner_trade_no>
     openid>".$dataArr['openid']."/openid>
     check_name>".$dataArr['check_name']."/check_name>
     re_user_name>".$dataArr['re_user_name']."/re_user_name>
     amount>".$dataArr['amount']."/amount>
     desc>".$dataArr['desc']."/desc>
     spbill_create_ip>".$dataArr['spbill_create_ip']."/spbill_create_ip>
     sign>".$sign."/sign>
     /xml>";
   return $data;

  }
  /**
  *   作用:格式化參數(shù),簽名過程需要使用
  */
  private function formatBizQueryParaMap($paraMap, $urlencode)
  {

   $buff = "";
   ksort($paraMap);
   foreach ($paraMap as $k => $v)
   {
     if($v){
      if($urlencode)
      {
        $v = urlencode($v);
      }

      $buff .= $k . "=" . $v . "";
     }

   }
   $reqPar=NULL;
   if (strlen($buff) > 0)
   {
     $reqPar = substr($buff, 0, strlen($buff)-1);
   }

   return $reqPar;
  }

  /**
  *   作用:生成簽名
  */
  private function getSign($Obj)
  {

   foreach ($Obj as $k => $v)
   {
     $Parameters[$k] = $v;
   }
   //簽名步驟一:按字典序排序參數(shù)
   ksort($Parameters);
   $String = $this->formatBizQueryParaMap($Parameters, false);
   //echo '【string1】'.$String.'/br>';
   //簽名步驟二:在string后加入KEY
   $String = $String."key=".$this->apikey;
   //echo "【string2】".$String."/br>";
   //簽名步驟三:MD5加密
   $String = md5($String);
   //echo "【string3】 ".$String."/br>";
   //簽名步驟四:所有字符轉(zhuǎn)為大寫
   $result_ = strtoupper($String);
   //echo "【result】 ".$result_."/br>";
   return $result_;
  }
  //-----------
  private function http($url, $method='POST', $postfields = null, $headers = array())
  {
   header("Content-Type:text/html;charset=utf-8");
   $ch = curl_init();
   /* Curl settings */
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_POSTFIELDS, "");
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https請求 不驗(yàn)證證書和hosts
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
   curl_setopt($ch, CURLOPT_TIMEOUT, 30);
   switch ($method){
     case 'POST':
      curl_setopt($ch,CURLOPT_POST, true);
      break;
   }
   curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
   curl_setopt($ch, CURLINFO_HEADER_OUT, true);
   $response = curl_exec($ch);
   $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //返回請求狀態(tài)碼
   curl_close($ch);
   return array($http_code, $response);
  }

}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • 微信企業(yè)轉(zhuǎn)賬之入口類分裝php代碼
  • php實(shí)現(xiàn)微信公眾號企業(yè)轉(zhuǎn)賬功能
  • PHP實(shí)現(xiàn)微信退款功能
  • PHP實(shí)現(xiàn)微信申請退款功能
  • PHP實(shí)現(xiàn)微信對賬單處理
  • php提取微信賬單的有效信息
  • 基于php的微信公眾平臺開發(fā)入門實(shí)例
  • php判斷頁面是否是微信打開的示例(微信打開網(wǎng)頁)
  • PHP對接微信公眾平臺消息接口開發(fā)流程教程
  • php實(shí)現(xiàn)微信企業(yè)轉(zhuǎn)賬功能

標(biāo)簽:綏化 辛集 鄂州 崇左 廊坊 太原 衡陽 白銀

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP APP微信提現(xiàn)接口代碼》,本文關(guān)鍵詞  PHP,APP,微信,提現(xiàn),接口,代碼,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP APP微信提現(xiàn)接口代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于PHP APP微信提現(xiàn)接口代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    聂拉木县| 井冈山市| 邢台市| 呈贡县| 甘洛县| 长垣县| 平邑县| 屏南县| 陈巴尔虎旗| 阳谷县| 铜川市| 五河县| 千阳县| 霍林郭勒市| 苏尼特左旗| 新晃| 海城市| 怀宁县| 抚州市| 鄢陵县| 成都市| 焦作市| 崇明县| 交城县| 牙克石市| 河东区| 崇义县| 西丰县| 桃园市| 肇庆市| 夏津县| 丰镇市| 青神县| 宜阳县| 大港区| 义马市| 同德县| 盘锦市| 中阳县| 巴彦县| 乐陵市|