提现必须得用双向证书、所以大家一定要在微信的商户平台找到相应的地方去设置、因为做这个提现已经有一段时间了、所以设置微信商户平台的那几个地方没有图的情况、也说不清楚、下次再做提现的时候、给大家分享如何设置商户平台那几个地方、不是很难、下面贴代码
注意事项:商户打款时是从商户可用余额中减钱,所以确保商户可用余额充足,同时注意官方文档中的付款规则;
封装提现的方法
function tixian($money){$appid = "################";//商户账号appid$secret = "##########";//api密码$mch_id = "#######";//商户号$mch_no = "#######";$openid="123456789";//授权用户openid$arr = array();$arr[mch_appid] = $appid;$arr[mchid] = $mch_id;$arr[
once_str] = ugv::randomid(20);//随机字符串,不长于32位$arr[partner_trade_no] = 1298016501 . date("Ymd") . rand(10000, 90000) . rand(10000, 90000);//商户订单号$arr[openid] = $openid;$arr[check_name] = NO_CHECK;//是否验证用户真实姓名,这里不验证$arr[amount] = $money;//付款金额,单位为分$desc = "###提现";$arr[desc] = $desc;//描述信息$arr[spbill_create_ip] = 192.168.0.1;//获取服务器的ip//封装的关于签名的算法$notify = new Notify_pub();$notify->weixin_app_config = array();$notify->weixin_app_config[KEY] = $mch_no;$arr[sign] = $notify->getSign($arr);//签名$var = $notify->arrayToXml($arr);$xml = $this->curl_post_ssl(https://api.mch./mmpaymkttransfers/promotion/transfers, $var, 30, array(), 1);$rdata = simplexml_load_string($xml, SimpleXMLElement, LIBXML_NOCDATA);$return_code = (string)$rdata->return_code;$result_code = (string)$rdata->result_code;$return_code = trim(strtoupper($return_code));$result_code = trim(strtoupper($result_code));if ($return_code == SUCCESS && $result_code == SUCCESS) {$isrr = array(con=>ok,error => 0,);} else {$returnmsg = (string)$rdata->return_msg;$isrr = array(error => 1,errmsg => $returnmsg,);}return json_encode($isrr);}
用到的curl_post_ssl()
function curl_post_ssl($url, $vars, $second = 30, $aHeader = array()){$isdir = "/cert/";//证书位置$ch = curl_init();//初始化curlcurl_setopt($ch, CURLOPT_TIMEOUT, $second);//设置执行最长秒数curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上curl_set