微信APP支付提现功能是我们常用的一个功能,接下来我们来对接APP的微信提现
业务范围 1.各类APP的提现功能为用户创造提现收益等
微信支付流程
1.选择接入模式 (商户平台申请)成为普通商户 2.参数申请 开放平台申请APPID ,商户号平台申请mchid 3.绑定APPID及mchid 4.配置API key API v3密钥主要用于平台证书解密、回调信息解密,具体使用方式可参见接口规则文档中证书和回调报文解密章节。请根据以下步骤配置API key:登录 微信商户平台,进入【账户中心 > API安全 > API安全】目录,点击【APIV3密钥】。 5.下载并配置商户证书,商户可登录微信商户平台,在【账户中心】->【API安全】->【API证书】目录下载证书 6.生成证书串 7. 详情可见 APP支付接入准备
tp6框架接入微信提现功能
你好!有很多人在接入微信支付时无从下下手,那么在本篇文件,带你详细的了解并实现微信支付,废话不多说,咱们开始
官方文档(多观察文档,和现成的代码就会发现微信支付的套路其实并不难)
微信支付官方文档
配置
'Wxpay_config' => array (
'appid' => '',
'secret' => '',
'mch_id' => '',
'api_key' => '',
'notify_url' => '',
'huiyuan_notify' => ''
),```
微信 控制器文件
private $SSLCERT_PATH = "/data/wxpay/apiclient_cert.pem";
private $SSLKEY_PATH = "/data/wxpay/apiclient_key.pem";
public function wxtransfer($openid,$trade_no,$money,$desc)
{
$data = [
'mch_appid' => config('app.Wxpay_config.appid'),
'mchid' => config('app.Wxpay_config.mch_id'),
'nonce_str' => $this->createNoncestr(),
'partner_trade_no' => $trade_no,
'openid' => $openid,
'check_name' => 'NO_CHECK',
'amount' => $money,
'desc' => $desc,
'spbill_create_ip' => $this->get_client_ip(),
];
$data['sign'] = $this->getSign($data);
$xmldata = $this->arrayToXml($data);
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
$res = $this->postXmlSSLCurl($xmldata,$url);
return $res;
}
function getSign($Obj)
{
foreach ($Obj as $k => $v)
{
$Parameters[strtolower($k)] = $v;
}
ksort($Parameters);
$String = $this->formatBizQueryParaMap($Parameters, false);
$String = $String."&key=".config('app.Wxpay_config.api_key');
$result_ = strtoupper(md5($String));
return $result_;
}
function arrayToXml($arr)
{
$xml = "<xml>";
foreach ($arr as $key=>$val)
{
if (is_numeric($val))
{
$xml.="<".$key.">".$val."</".$key.">";
}
else
$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
}
$xml.="</xml>";
return $xml;
}
function formatBizQueryParaMap($paraMap, $urlencode)
{
$buff = "";
ksort($paraMap);
foreach ($paraMap as $k => $v)
{
if($urlencode)
{
$v = urlencode($v);
}
$buff .= strtolower($k) . "=" . $v . "&";
}
$reqPar = '';
if (strlen($buff) > 0)
{
$reqPar = substr($buff, 0, strlen($buff)-1);
}
return $reqPar;
}
private function postXmlSSLCurl($xml,$url,$second=30)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_TIMEOUT,$second);
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_SSLCERTTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLCERT, $this->SSLCERT_PATH);
curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLKEY,$this->SSLKEY_PATH);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
$data = curl_exec($ch);
if($data){
curl_close($ch);
return $data;
}
else {
$error = curl_errno($ch);
echo "curl出错,错误码:$error"."<br>";
curl_close($ch);
return false;
}
}
|