根据微信小程序API文档企业付款到零钱具体PHP方法直接上代码
public function payFwxPrice($appid,$mchid,$price,$openid,$desc='测试',$check_name=''){ $key='*****';//从微信公众平台获取的¥jey $total_amount = (100) * $price; $data=array( 'mch_appid'=>$appid,//商户账号appid 'mchid'=>$mchid, //商户号 'nonce_str'=>$this->RandStr(32),//随机字符串 'partner_trade_no'=> date('ymdhis').rand(1000,9999),//商户订单号 'openid'=> $openid,//用户openid 'check_name'=>'NO_CHECK',//校验用户姓名选项, 'amount'=>$total_amount,//金额 'desc'=> $desc,//企业付款描述信息 'spbill_create_ip'=> '**********',//ip地址 ); $secrect_key=$key;///这个就是个api密码。md5 32位。 $data=array_filter($data); ksort($data); $str=''; foreach($data as $k=>$v) { $str.=$k.'='.$v.'&'; } $str.='key='.$secrect_key; $data['sign']=md5($str); //生成签名算法 $xml=$this->arrayToXml($data); $url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; //调用接口 $res=$this::curl_post_ssl($url,$xml); $return=$this->xmlToArray($res); return $return; } //数组转换成xml private function arrayToXml($arr) { $xml = "<xml>"; foreach ($arr as $key => $val) { if (is_array($val)) { $xml .= "<" . $key . ">" . arrayToXml($val) . "</" . $key . ">"; } else { $xml .= "<" . $key . ">" . $val . "</" . $key . ">"; } } $xml .= "</xml>"; return $xml; } //xml转换成数组 private function xmlToArray($xml) { //禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $val = json_decode(json_encode($xmlstring), true); return $val; }
John Doe
Jan 08, 2021 14:41 pm根据微信小程序API文档企业付款到零钱具体PHP方法直接上代码
给他点赞