php 에서 애플 릿 코드 구현 코드 가 져 오기(B 클래스 인터페이스)
애플 릿 코드 생 성 pp 코드
public function qrcode(){
$member_id = session('id');
if(empty($member_id)) $this->error(' ');
//
$member = model('Member')->where('id',$member_id)->find();
if($member['is_share'] && $member['share_qrcode']){
$litpic = $member['share_qrcode'];
}else{
header('content-type:image/jpg');//
//
$wechatObj = new \Wechat();// appid
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$wechatObj->getAccessToken();
$page = 'pages/index/index';
$scene = 'share_id='.$member_id;
$path = './upload/qrcode/'.$member_id.'.jpg';
$postData = array();
$postData['page'] = $page;
$postData['scene'] = $scene;
$data = json_encode($postData);
$result = $this->api_notice_increment($url,$data);
$image = 'data:image/jpg;base64,' . base64_encode($result);
$other_result = $result;
$file = fopen($path,"w");//
fwrite($file,$other_result);//
fclose($file);//
//return $result;
$litpic = $path;
$litpic = ltrim($litpic,'.');
//
$member->save(['share_qrcode'=>$litpic,'is_share'=>1]);
}
//
$path_member = model('Member')->where('path',$member_id)->field('id,name,litpic,add_time')->select();
$path = [];
foreach($path_member as $v){
$v['add_time'] = date('Y-m-d H:i:s',$v['add_time']);
$path[] = $v;
}
$data = [
'litpic' => $litpic,
'path' => $path,
];
return json($data);
}
public function api_notice_increment($url,$data){
//return $data;
$curl = curl_init(); // CURL
//$header = "Accept-Charset: utf-8";
curl_setopt($curl, CURLOPT_URL, $url); //
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // SSL
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); //
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); //
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Referer
curl_setopt($curl, CURLOPT_POST, 1); // Post
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post
curl_setopt($curl, CURLOPT_TIMEOUT, 30); //
curl_setopt($curl, CURLOPT_HEADER, 0); // Header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //
$tmpInfo = curl_exec($curl); //
if (curl_errno($curl)) {
echo 'Errno'.curl_error($curl);
}
curl_close($curl); // CURL
return $tmpInfo; //
}
function api_notice_increment($url,$data)
{
$curl = curl_init();
$a = strlen($data);
$header = array("Content-Type: application/json; charset=utf-8","Content-Length: $a");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
애플 릿 에서 QR 코드 에 있 는 인 자 를 가 져 옵 니 다.
/**
* --
*/
onLoad: function(option) {
console.log(option)
if(option.id){
this.setData({ id: option.id });
this.data.business_id = option.id;
this.loadData(option.id);
}
//
if (option.scene){
const ids = decodeURIComponent(option.scene).split('=')[1];
console.log("ids", ids);
this.setData({ id: ids });
this.data.business_id = ids;
this.loadData(ids);
}
},
wechat 클래스 추가
<?php
class Wechat
{
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public $table;
public $where_web;
public $wechatId;
public $wechatToken;
public $wechatAppid;
public $wechatAppsecret;
public $wechatMchid;
public $wechatPrivatekey;
public $wechatAccessToken;
public $wechatAccessTokenTime;
public $wechatJsapiTicket;
public $wechatJsapiTicketTime;
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public function __construct() {
//
/*$this->wechatId = 1;
$this->wechatAppid = 'wx1161dbcdd18c52c2';
$this->wechatAppsecret = 'f373410716a198feb462182c69facb8a';
$this->wechatMchid = 1493574822;
$this->wechatPrivatekey = md5(123);
*/
// appid
$this->wechatId = 1;
$this->wechatAppid = 'your appid';
$this->wechatAppsecret = 'your appsecret';
$this->wechatMchid = ;
$this->wechatPrivatekey = ' ';
/*
$this->wechatToken = $WechatInfo['wechat_token'];
$this->wechatAccessToken = $WechatInfo['wechat_access_token'];
$this->wechatAccessTokenTime = $WechatInfo['wechat_access_token_time'];
$this->wechatJsapiTicket = $WechatInfo['wechat_jsapi_ticket'];
$this->wechatJsapiTicketTime = $WechatInfo['wechat_jsapi_ticket_time'];
*/
}
// +----------------------------------------------------------------------
// | access_token
// +----------------------------------------------------------------------
public function getAccessToken(){
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this->wechatAppid.'&secret='.$this->wechatAppsecret;
$data = $this -> curlGet($url);
$access_token = $data['access_token'];
$expires_in = $data['expires_in'];
$save['wechat_access_token'] = $access_token;
$save['wechat_access_token_time'] = ($expires_in+time())-360;
$this -> wechatAccessToken = $save['wechat_access_token'];
$this -> wechatAccessTokenTime = $save['wechat_access_token_time'];
return $access_token;
}
// +----------------------------------------------------------------------
// | access_token
// +----------------------------------------------------------------------
public function getJsapiTicket(){
$url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$this -> getAccessToken().'&type=jsapi';
$data = $this -> curlGet($url);
$jsapi_ticket = $data['ticket'];
$expires_in = $data['expires_in'];
$save['wechat_jsapi_ticket'] = $jsapi_ticket;
$save['wechat_jsapi_ticket_time'] = ($expires_in+time())-360;
$this->wechatJsapiTicket = $save['wechat_jsapi_ticket'];
$this->wechatJsapiTicketTime = $save['wechat_jsapi_ticket_time'];
return $jsapi_ticket;
}
// +----------------------------------------------------------------------
// | signature
// +----------------------------------------------------------------------
public function getSignature($appId,$timestamp,$nonceStr,$url)
{
$jsapi_ticket = $this -> getJsapiTicket();
$string1 = "jsapi_ticket={$jsapi_ticket}&noncestr={$nonceStr}×tamp={$timestamp}&url={$url}";
$signature = sha1($string1);
return $signature;
}
// +----------------------------------------------------------------------
// | createNonceStr
// +----------------------------------------------------------------------
public function getCreateNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public function curlDownload($url,$name)
{
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_URL, $url );
ob_start ();
curl_exec ( $ch );
$return_content = ob_get_contents ();
ob_end_clean ();
$return_code = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
$filename = "Uploads/Card/{$name}";
$fp= @fopen($filename,"a");
fwrite($fp,$return_content);
// URL
curl_close($ch);
$url = "/Uploads/Card/{$name}";
return "{$url}";
}
// +----------------------------------------------------------------------
// | GET
// +----------------------------------------------------------------------
public function curlGet($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
return $jsoninfo;
}
// +----------------------------------------------------------------------
// | POST SSL
// +----------------------------------------------------------------------
public function curlPostSSL($url, $vars, $second=30,$aHeader=array()){
$ch = curl_init();
//
curl_setopt($ch,CURLOPT_TIMEOUT,$second);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
// ,
curl_setopt($ch,CURLOPT_URL,$url);
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,getcwd().'/cert/apiclient_cert.pem');
//curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLKEY,getcwd().'/cert/apiclient_key.pem');
if( count($aHeader) >= 1 ){
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
}
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
$data = curl_exec($ch);
if($data){
curl_close($ch);
return $data;
} else {
$error = curl_errno($ch);
echo "call faild, errorCode:$error
";
curl_close($ch);
return false;
}
}
// +----------------------------------------------------------------------
// |
// out_trade_no
// total_fee
// refund_fee
// +----------------------------------------------------------------------
public function refund($out_trade_no,$total_fee,$refund_fee){
$arr['appid'] = $this->wechatAppid;
$arr['mch_id'] = $this->wechatMchid;
$arr['nonce_str'] = $this->getNonceStr();
$arr['out_trade_no'] = $out_trade_no;
$arr['out_refund_no'] = $this->getNonceStr();
$arr['total_fee'] = $total_fee;
$arr['refund_fee'] = $refund_fee;
$arr['sign'] = $this->MakeSign($arr);
// xml
$xml = $this->ToXml($arr);
//post xml
$url = "https://api.mch.weixin.qq.com/secapi/pay/refund";;// ,post
$ch=curl_init();
// URL , curl_init() 。
curl_setopt($ch,CURLOPT_URL,$url);
// 。
//curl_setopt($ch,CURLOPT_HEADER,1);
// curl_exec() , 。
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
// 。 "PEM" ( ), "DER" "ENG"。
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
// PEM 。
curl_setopt($ch,CURLOPT_SSLCERT,GEN.'/cert/apiclient_cert.pem');
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
curl_setopt($ch,CURLOPT_TIMEOUT,30);
// SSL 。
curl_setopt($ch,CURLOPT_SSLKEY,GEN.'/cert/apiclient_key.pem');
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
// 1 。 CURLOPT_SSL_VERIFYPEER 。 .
// curl_setopt($ch,CURLOPT_CAINFO,getcwd().'/cert/rootca.pem');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
$data=curl_exec($ch);
if($data){
curl_close($ch);
$data_arr = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $data_arr;
}else{
$error = curl_errno($ch);
return "curl :".$error;
}
}
// +----------------------------------------------------------------------
// |
// out_trade_no
// total_fee
// refund_fee
// +----------------------------------------------------------------------
public function payment($partner_trade_no,$openid,$amount,$desc){
//
$arr['mch_appid'] = $this->wechatAppid;
$arr['mchid'] = $this->wechatMchid;
$arr['nonce_str'] = $this->getNonceStr();
$arr['partner_trade_no'] = $partner_trade_no;
$arr['openid'] = $openid;
$arr['check_name'] = "NO_CHECK";
$arr['amount'] = $amount*100;
$arr['desc'] = $desc;
$arr['spbill_create_ip'] = request()->ip();
$arr['sign'] = $this->MakeSign($arr);
// xml
$xml = $this->ToXml($arr);
//post xml
$url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";// ,post
$ch=curl_init();
// URL , curl_init() 。
curl_setopt($ch,CURLOPT_URL,$url);
// 。
//curl_setopt($ch,CURLOPT_HEADER,1);
// curl_exec() , 。
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
// 。 "PEM" ( ), "DER" "ENG"。
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
// PEM 。
curl_setopt($ch,CURLOPT_SSLCERT,GEN.'/cert/apiclient_cert.pem');
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
curl_setopt($ch,CURLOPT_TIMEOUT,30);
// SSL 。
curl_setopt($ch,CURLOPT_SSLKEY,GEN.'/cert/apiclient_key.pem');
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
// 1 。 CURLOPT_SSL_VERIFYPEER 。 .
// curl_setopt($ch,CURLOPT_CAINFO,getcwd().'/cert/rootca.pem');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
$data=curl_exec($ch);
if($data){
curl_close($ch);
$data_arr = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $data_arr;
}else{
$error = curl_errno($ch);
return "curl :".$error;
}
}
// +----------------------------------------------------------------------
// | POST
// +----------------------------------------------------------------------
public function curlPost($url,$post_data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($post_data)){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
return $output;
}
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public function message($mobile){
$info = M('web')
-> find();
$post_data = array();
$post_data['userid'] = $info['message_id'];
$post_data['account'] = $info['message_account'];
$post_data['password'] = $info['message_password'];
$code = rand(1111,9999);
session('code',$code);
$post_data['content'] = $info['message_autograph'].' :'.$code.' , ';
$post_data['mobile'] = $mobile;
$post_data['sendtime'] = date('Y-m-d');
$url='http://pt.sdqlweb.com/sms.aspx?action=send';
$o='';
foreach ($post_data as $k=>$v)
{
$o.="$k=".urlencode($v).'&';
}
$post_data=substr($o,0,-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$data = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
curl_close($ch);
return $data;
}
// +----------------------------------------------------------------------
// | post xml url
// +----------------------------------------------------------------------
public function postXmlCurl($xml, $url, $useCert = false, $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,2);//
// header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//post
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
// curl
$data = curl_exec($ch);
//
if($data){
curl_close($ch);
return $data;
} else {
$error = curl_errno($ch);
curl_close($ch);
}
}
// +----------------------------------------------------------------------
// | xml
// +----------------------------------------------------------------------
public function ToXml($array)
{
if(!is_array($array)
|| count($array) <= 0)
{
throw new WxPayException(" !");
}
$xml = "<xml>";
foreach ($array as $key=>$val)
{
if (is_numeric($val)){
$xml.="<".$key.">".$val."</".$key.">";
}else{
$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
}
}
$xml.="</xml>";
return $xml;
}
// +----------------------------------------------------------------------
// | RAS
// +----------------------------------------------------------------------
public function get_pub_key(){
$url = "https://fraud.mch.weixin.qq.com/risk/getpublickey";
$arr['mch_id'] = $this->wechatMchid;
$arr['nonce_str'] = $this->getNonceStr();
$arr['sign_type'] = 'MD5';
$arr['sign'] = $this->MakeSign($arr);
$xml = $this->ToXml($arr);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
curl_setopt($ch,CURLOPT_SSLCERT,getcwd().'/cert/apiclient_cert.pem');
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
curl_setopt($ch,CURLOPT_SSLKEY,getcwd().'/cert/apiclient_key.pem');
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
curl_setopt($ch,CURLOPT_CAINFO,getcwd().'/cert/rootca.pem');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
$data = $this->FromXml(curl_exec($ch));
//
$TxtFileName = "./cert/public.pem";
// ,
if( ($TxtRes=fopen ($TxtFileName,"w+")) === false){
echo(" :".$TxtFileName." ");
exit();
}
echo (" ".$TxtFileName." !</br>");
$StrConents = $data['pub_key'];//
if(!fwrite ($TxtRes,$StrConents)){ //
echo (" ".$TxtFileName." ".$StrConents." !");
fclose($TxtRes);
exit();
}
echo (" ".$TxtFileName." ".$StrConents." !");
fclose ($TxtRes); //
}
// +----------------------------------------------------------------------
// | xml array
// +----------------------------------------------------------------------
public function FromXml($xml)
{
// xml
libxml_disable_entity_loader(true);
$this->values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $this->values;
}
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public function Cardcode($card_name)
{
$arr = array(
' '=>1002,
' '=>1005,
' '=>1026,
' '=>1003,
' '=>1001,
' '=>1066,
' '=>1020,
' '=>1004,
' '=>1006,
' '=>1009,
' '=>1010,
' '=>1021,
' '=>1025,
' '=>1027,
' '=>1022,
' '=>1032,
' '=>1056
);
foreach($arr as $k=>$v){
if($k == $card_name){
return $v;
}
}
}
// +----------------------------------------------------------------------
// | url
// +----------------------------------------------------------------------
public function ToUrlParams($array)
{
$buff = "";
foreach ($array as $k => $v)
{
if($k != "sign" && $v != "" && !is_array($v)){
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
// +----------------------------------------------------------------------
// | sign , SetSign
// +----------------------------------------------------------------------
public function MakeSign($array)
{
// :
ksort($array);
$string = $this->ToUrlParams($array);
// : string KEY
$string = $string."&key=".$this->wechatPrivatekey;
// :MD5
$string = md5($string);
// :
$string = strtoupper($string);
return $string;
}
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public function getNonceStr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str ="";
for ( $i = 0; $i < $length; $i++ ) {
$str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
}
return $str;
}
// +----------------------------------------------------------------------
// | log
// +----------------------------------------------------------------------
public function save_log($msg){
error_log(date("Y-m-d H:i:s")."\r
".print_r($msg,1)."\r
\r
\r
",3,'./error.log');
}
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public function curlImg($images){
$url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=".$this->getAccessToken()."&type=image";
$ch1 = curl_init ();
$timeout = 5;
$real_path = "{$_SERVER['DOCUMENT_ROOT']}{$images}";
$data= array("media"=>"@{$real_path}",'form-data'=>$file_info);
curl_setopt ( $ch1, CURLOPT_URL, $url );
curl_setopt ( $ch1, CURLOPT_POST, 1 );
curl_setopt ( $ch1, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch1, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt ( $ch1, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch1, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt ( $ch1, CURLOPT_POSTFIELDS, $data );
$result = curl_exec ( $ch1 );
curl_close ( $ch1 );
if(curl_errno()==0){
$result=json_decode($result,true);
return $result;
}else {
return false;
}
}
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public function wechatText($content){
$parrent = "/<[img|IMG].*?src='(.*?)'/";
$str = html_entity_decode($content);
preg_match_all($parrent,$str,$match);
foreach( $match[1] as $v){
$imgurl = $this->curlImg($v);
$content = str_replace($v,$imgurl['url'],$content);
}
return ($content);
}
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
public function check_bank_card($card){
$url = "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo={$card}&cardBinCheck=true";
$data = $this->curlGet($url);
$name = [
"SRCB"=> " ",
"BGB"=> " ",
"SHRCB"=> " ",
"BJBANK"=> " ",
"WHCCB"=> " ",
"BOZK"=> " ",
"KORLABANK"=> " ",
"SPABANK"=> " ",
"SDEB"=> " ",
"HURCB"=> " ",
"WRCB"=> " ",
"BOCY"=> " ",
"CZBANK"=> " ",
"HDBANK"=> " ",
"BOC"=> " ",
"BOD"=> " ",
"CCB"=> " ",
"ZYCBANK"=> " ",
"SXCB"=> " ",
"GZRCU"=> " ",
"ZJKCCB"=> " ",
"BOJZ"=> " ",
"BOP"=> " ",
"HKB"=> " ",
"SPDB"=> " ",
"NXRCU"=> " ",
"NYNB"=> " ",
"GRCB"=> " ",
"BOSZ"=> " ",
"HZCB"=> " ",
"HSBK"=> " ",
"HBC"=> " ",
"JXBANK"=> " ",
"HRXJB"=> " ",
"BODD"=> " ",
"AYCB"=> " ",
"EGBANK"=> " ",
"CDB"=> " ",
"TCRCB"=> " ",
"NJCB"=> " ",
"ZZBANK"=> " ",
"DYCB"=> " ",
"YBCCB"=> " ",
"SCRCU"=> " ",
"KLB"=> " ",
"LSBANK"=> " ",
"YDRCB"=> " ",
"CCQTGB"=> " ",
"FDB"=> " ",
"JSRCU"=> " ",
"JNBANK"=> " ",
"CMB"=> " ",
"JINCHB"=> " JCBANK",
"FXCB"=> " ",
"WHRCB"=> " ",
"HBYCBANK"=> " ",
"TZCB"=> " ",
"TACCB"=> " ",
"XCYH"=> " ",
"CEB"=> " ",
"NXBANK"=> " ",
"HSBANK"=> " ",
"JJBANK"=> " ",
"NHQS"=> " ",
"MTBANK"=> " ",
"LANGFB"=> " ",
"ASCB"=> " ",
"KSRB"=> " ",
"YXCCB"=> " ",
"DLB"=> " ",
"DRCBCL"=> " ",
"GCB"=> " ",
"NBBANK"=> " ",
"BOYK"=> " ",
"SXRCCU"=> " ",
"GLBANK"=> " ",
"BOQH"=> " ",
"CDRCB"=> " ",
"QDCCB"=> " ",
"HKBEA"=> " ",
"HBHSBANK"=> " ",
"WZCB"=> " ",
"TRCB"=> " ",
"QLBANK"=> " ",
"GDRCC"=> " ",
"ZJTLCB"=> " ",
"GZB"=> " ",
"GYCB"=> " ",
"CQBANK"=> " ",
"DAQINGB"=> " ",
"CGNB"=> " ",
"SCCB"=> " ",
"CSRCB"=> " ",
"SHBANK"=> " ",
"JLBANK"=> " ",
"CZRCB"=> " ",
"BANKWF"=> " ",
"ZRCBANK"=> " ",
"FJHXBC"=> " ",
"ZJNX"=> " ",
"LZYH"=> " ",
"JSB"=> " ",
"BOHAIB"=> " ",
"CZCB"=> " ",
"YQCCB"=> " ",
"SJBANK"=> " ",
"XABANK"=> " ",
"BSB"=> " ",
"JSBANK"=> " ",
"FSCB"=> " ",
"HNRCU"=> " ",
"COMM"=> " ",
"XTB"=> " ",
"CITIC"=> " ",
"HXBANK"=> " ",
"HNRCC"=> " ",
"DYCCB"=> " ",
"ORBANK"=> " ",
"BJRCB"=> " ",
"XYBANK"=> " ",
"ZGCCB"=> " ",
"CDCB"=> " ",
"HANABANK"=> " ",
"CMBC"=> " ",
"LYBANK"=> " ",
"GDB"=> " ",
"ZBCB"=> " ",
"CBKF"=> " ",
"H3CB"=> " ",
"CIB"=> " ",
"CRCBANK"=> " ",
"SZSBK"=> " ",
"DZBANK"=> " ",
"SRBANK"=> " ",
"LSCCB"=> " ",
"JXRCU"=> " ",
"ICBC"=> " ",
"JZBANK"=> " ",
"HZCCB"=> " ",
"NHB"=> " ",
"XXBANK"=> " ",
"JRCB"=> " ",
"YNRCC"=> " ",
"ABC"=> " ",
"GXRCU"=> " ",
"PSBC"=> " ",
"BZMD"=> " ",
"ARCU"=> " ",
"GSRCU"=> " ",
"LYCB"=> " ",
"JLRCU"=> " ",
"URMQCCB"=> " ",
"XLBANK"=> " ",
"CSCB"=> " ",
"JHBANK"=> " ",
"BHB"=> " ",
"NBYZ"=> " ",
"LSBC"=> " ",
"BOCD"=> " ",
"SDRCU"=> " ",
"NCB"=> " ",
"TCCB"=> " ",
"WJRCB"=> " ",
"CBBQS"=> " ",
"HBRCU"=> " "
];
$bank = $data['bank'];
$name = $name[$bank];
if($name){
if($bank){
$url1 = "https://apimg.alipay.com/combo.png?d=cashier&t={$bank}";
$msg['pic'] = $this->curlDownload($url1,time().'.png');
$msg['logo'] = $this->imagecropper('.'.$msg['pic'],30,35);
$msg['status'] = 200;
$msg['name'] = $name;
return $msg;
}
}else{
$msg['status'] = 500;
$msg['data'] = ' , ';
return $msg;
}
}
/**
*
* @param $title string
* @param $content string
* @param $encode string
*/
public function imagecropper($source_path, $target_width, $target_height){
$source_info = getimagesize($source_path);
$source_width = $source_info[0];
$source_height = $source_info[1];
$source_mime = $source_info['mime'];
$source_x = 0;
$source_y = 0;
switch ($source_mime)
{
case 'image/gif':
$source_image = imagecreatefromgif($source_path);
break;
case 'image/jpeg':
$source_image = imagecreatefromjpeg($source_path);
break;
case 'image/png':
$source_image = imagecreatefrompng($source_path);
break;
default:
return false;
break;
}
$target_image = imagecreatetruecolor($target_width, $target_height);
$cropped_image = imagecreatetruecolor($target_width, $target_height);
//
imagecopy($cropped_image, $source_image,0,0, $source_x, $source_y, $target_width, $target_height);
//
imagecopyresampled($target_image, $cropped_image, 0, 0, 0, 0, $target_width, $target_height, $target_width, $target_height);
imagecolortransparent($target_image,imagecolorallocate($target_image,255,255,255));
$fileName = time()."1.png";
$path = './Uploads/Card/'.$fileName;
imagepng($target_image,$path);
return '/Uploads/Card/'.$fileName;
}
//
public function noncestr($length = 12){
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$str ="";
for ( $i = 0; $i < $length; $i++ ) {
$str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
}
return $str;
}
}
?>
다음은 다른 네티즌 의 보충PHP 에서 애플 릿 코드 를 가 져 오고 전단 으로 그림 을 보 여 줍 니 다.
작은 프로그램의 QR 코드 는 작은 프로그램 코드 와 QR 코드 로 나 뉜 다.
애플 릿 QR 코드 문 서 를 만 드 는 데 백 엔 드 가 생 성 된다 고 합 니 다.
애플 릿 개발 문서 자료 참조:https://developers.weixin.qq.com/miniprogram/dev/api/getWXACodeUnlimit.html
문서 의 매개 변수 소 개 는 매우 상세 하지만 구체 적 인 demo 가 없습니다.요청 한 인터페이스 에 대한 반환 값 은 진 흐름(즉 브 라 우 저 에 어 지 러 운 코드 를 표시 하 는 것)도 매우 괴 롭 습 니 다.여기에 제 코드 를 붙 여 주세요.
// , A
public function getQRCodeAction()
{
$data['scene'] = $this->_req->getQuery('shareId',11); //scence、page ( :scene 32 )
$data['width'] = $this->_req->getQuery('width',220);
$data['auto_color'] = $this->_req->getQuery('auto_color');
$data['line_color'] = $this->_req->getQuery('line_color');
$data['is_hyaline'] = $this->_req->getQuery('is_hyaline',true);
$data['page'] = $this->_req->getQuery('page',""); // ,
$wxModel = new WxAuthModel();
$token = $wxModel->getAccessToken();
$res_url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$token"; //
header('content-type:image/png');
$data = json_encode($data);
$Qr_code = $wxModel->http_request($res_url,$data); // , ,
file_put_contents('/tmp/qr_code.png', $Qr_code); //
$img_string = $this->fileToBase64('/tmp/qr_code.png'); // base64
response::result($img_string);
}
// base64
private function fileToBase64($file){
$base64_file = '';
if(file_exists($file)){
$mime_type= mime_content_type($file); // , mine_type='image/png', , mine_type text/plain
$base64_data = base64_encode(file_get_contents($file));
$base64_file = 'data:'.$mime_type.';base64,'.$base64_data; //$base64_file = 'data:image/png;base64,'.$base64_data;
}
return $base64_file;
}
/* access_token, code , token*/
public function getAccessToken()
{
$token_file = '/dev/shm/heka2_token.json'; // token , token ( ),
$data = json_decode(file_get_contents($token_file));
if ($data->expire_time < time()) {
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
$res = json_decode($this->http_request($url));
$access_token = $res->access_token;
if ($access_token) {
$data->expire_time = time() + 7000;
$data->access_token = $access_token;
file_put_contents($token_file, json_encode($data));
}
} else {
$access_token = $data->access_token;
}
return $access_token;
}
완전한 PHP 가 실 현 된 코드 를 아직 찾 지 못 한 것 같 습 니 다.이것 은 제 가 사용 하 는 것 이 괜 찮 습 니 다.부적 절 한 점 이 있 으 면 지적 해 주세요~
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Laravel - 변환된 유효성 검사 규칙으로 API 요청 제공동적 콘텐츠를 위해 API를 통해 Laravel CMS에 연결하는 모바일 앱(또는 웹사이트) 구축을 고려하십시오. 이제 앱은 CMS에서 번역된 콘텐츠를 받을 것으로 예상되는 다국어 앱이 될 수 있습니다. 일반적으로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.