php微信小程序生成二维码,出现乱码,{"errcode":44002,"errmsg":"empty post data"},'{"errcode":41001,"errmsg":"access_t

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43202928/article/details/89847950

微信小程序的坑简直比我的头发还多,今天下午获取微信二维码,遇到的44002,41001,还有图片没法正常显示以及小程序参数获取的问题,接下来一一解决

首先获取微信token然后再获取二维码这个没什么好说的 直接上代码

public function getQRcode()
{
$appid = ‘wx3118da96194edcd5’;
$secret = ‘15de113e48ddcfd8226afc701ee938eb’;
KaTeX parse error: Expected 'EOF', got '&' at position 115: …ient_credential&̲appid='.appid.’&secret=’.$secret),true)[‘access_token’];
url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?accesstoken=url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=access_token";
$ch = curl_init();
KaTeX parse error: Expected 'EOF', got '&' at position 33: …e(['scene' => '&̲id='.this->user_id]);
curl_setopt(ch,CURLOPTPOST,1);curlsetopt(ch, CURLOPT_POST, 1); curl_setopt(ch, CURLOPT_HEADER, ‘image/gif’);
curl_setopt(ch,CURLOPTURL,ch, CURLOPT_URL,url);
curl_setopt(ch,CURLOPTPOSTFIELDS,ch, CURLOPT_POSTFIELDS,data);
curl_setopt(ch,CURLOPTSSLVERIFYPEER,false);curlsetopt(ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt(ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'Content-Length: ’ . strlen(data)));curlsetopt(data) )); curl_setopt(ch, CURLOPT_RETURNTRANSFER,1); //如果需要将结果直接返回到变量里,那加上这句。
res=curlexec(res = curl_exec(ch);
}

虽然已经获取到了小程序二维码 但是此时打印$res就会出现乱码的问题 仔细看文档的同学可能就知道 这是因为微信会返回图片二进制内容

妈的 简直不要太坑啊

data=data:image/jpeg;base64,.base64encode(data = 'data:image/jpeg;base64,'.base64_encode(res);//补全base64加密字符串头
html="<!DOCTYPEhtml><htmllang=en><head><metacharset=UTF8><title></title></head><body><imgsrc=html = "<!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <title>二维码</title> </head> <body> <img src='data’>

";
echo $html;

在代码上加上这一句 可以转换 直接输出图片

ok 二维码已经出来了 接下来就是获取二维码参数 比如参数为id=1

获取二维码参数还是比较简单的 微信二维码指向首页
然后在index.js编写

onLoad (option) { console.log(option) }

然后请求后台交互 将参数传过去 ,本来后台接口已经写好了 我想今天的工作可以告一段段落了,尼玛没想到检查数据的时候发现id根本没有获取到

在本地测试的时候可以

在这里插入图片描述

这样操作开发工具 就会获取到参数 接着去后台打印的时候你就会发现你传过去的参数根本不是1,而是{‘id’:‘1’},我日 就没遇到过他们这种的

所以如果本地测试的话还得需要进行一下操作 兄弟我是直接被征服了 随便截取了一下1前边的7个字符 后边的2个字符 这样才得到完整’1‘,

尼玛,这个小程序简直不要太坑

展开阅读全文

"errcode":41001,"errmsg":"access_token missing hint: [vqDZeA0872sz12!]"

05-18

执行结果rn"access_token":"_DxA7FQX9By8dEtqBSiJGZ695SavKrl-B-jvDowqdEX_YNFDPYgzCUqVGONuL2zHgFYu8gSJm74pX00obbGcGo6NpLZkfm_Dqh3-44jfKFu_Ry1zlXfcNPjt2wmPO2o9HFPjAFADBL","expires_in":7200rnrnrn_DxA7FQX9By8dEtqBSiJGZ695SavKrl-B-jvDowqdEX_YNFDPYgzCUqVGONuL2zHgFYu8gSJm74pX00obbGcGo6NpLZkfm_Dqh3-44jfKFu_Ry1zlXfcNPjt2wmPO2o9HFPjAFADBLrnrn"errcode":41001,"errmsg":"access_token missing hint: [vqDZeA0872sz12!]"rnrnrnrn错误提示:[color=#FF0000]"errcode":41001,"errmsg":"access_token missing hint: [vqDZeA0872sz12!]"[/color]rn这个是过期提示啊,我刚获取马上过期,我很糊涂。rnrn这个是asp源码:rnshuju = "template_id=1&aa=b"rnurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN"rnrnrn'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=XX&secret=XXrnrn'获取 access_tokenrnshuju = "grant_type=client_credential&appid=XX&secret=XX"rnurl = "https://api.weixin.qq.com/cgi-bin/token?"rnrnrnrnjieguo = PostHTTPPage(url,shuju,"post") '获得 access_tokenrnresponse.write jieguo & " "rnrnjieguo_er = split(jieguo,",")rnjieguo_er2 = jieguo_er(0)rnjieguo_er222 = split(jieguo_er2,Chr(34))rnrnresponse.write " "rnaccess_token = jieguo_er222(3)rnresponse.write jieguo_er222(3) '真的,access_tokenrnrn'https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKENrnrnresponse.write " "rnshuju = "access_token=3O6MBA_7lFQw7gdGbZ33MLSTgm8fYiGCxmfuNThWAntpoeJIksvgmbGYws-YQsMCc_nFYEancPPeDbdo99GA7w5mif2hE6EWd0-3PbMPLsqVtNhZUvJOU-ZD0UWnxjPFSCBhADAGQP"rnurl = "https://api.weixin.qq.com/cgi-bin/getcallbackip?"rnrnjieguo22 = PostHTTPPage(url,shuju,"get") '获得 access_tokenrnresponse.write jieguo22 & " "rnrn'shuju = "access_token=RTxWjwYCXKgoeiS74gqkZauP4TfaOQLByNwPxqFU_CPuX6_z_dg7w_O_K3s3-Zpu_RmEQ9DqpLPSAgj_oHfpKh12QR8NsZ56NaSD-KGtRNlAM3WtGwHmlRBySN5D6OyIYAQjAFAQSI"rn'url = "https://api.weixin.qq.com/cgi-bin/message/template/send?"rnrnfunction BytesToBstr(body,Cset) rndim objstream rnset objstream = Server.CreateObject("adodb.stream")rnobjstream.Type = 1 rnobjstream.Mode =3 rnobjstream.Open rnobjstream.Write body rnobjstream.Position = 0 rnobjstream.Type = 2 rnobjstream.Charset = Cset rnBytesToBstr = objstream.ReadText rnobjstream.Close rnset objstream = nothing rnEnd functionrnrnrnrnfunction PostHTTPPage(url,data,fangshi) rndim Http rnset Http=server.createobject("MSXML2.SERVERXMLHTTP.3.0")rnHttp.open fangshi,url,false rnHttp.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded" rnHttp.send(data) rnif Http.readystate<>4 then rnexit function rnEnd ifrnPostHTTPPage=bytesToBSTR(Http.responseBody,"utf-8") rnset http=nothing rnif err.number<>0 then err.Clear rnEnd function 论坛

"errcode":40163,"errmsg":"code been used

06-28

刚刚接触 微信开发 被这个40163 困扰好多天了,心态崩了,求大神解决.直接上代码rn用的是微信测试号开发,ngrok映射工具rn现在的问题是rn[color=#FF0000]第一个用户可以顺利获取到openid,后面的用户就获取不到了[/color]rn,每一次生成的code也是新的,但就是没有用,心态爆炸[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/1.gif][/img]rn拦截器代码rn[code=java]rnprivate static final String APPID = "??";rn private static final String SCOPE = "snsapi_base";rn private static String REDIRECT_URI = "https://b3d6bc4a.ngrok.io/WeChat/getOpenid.do";rn private static String URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";rnrn @Overridern public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)rn throws Exception rn HttpSession session = request.getSession();rn String openid = (String) request.getSession().getAttribute("openid");rn if (openid == null) rn REDIRECT_URI = UrlUtil.getURLEncoderString(REDIRECT_URI);rn URL = URL.replace("APPID", APPID).replace("REDIRECT_URI", REDIRECT_URI).replace("SCOPE", SCOPE);rn session.setAttribute("reqPath", request.getServletPath());rn response.sendRedirect(URL);rn session.setAttribute("URL", URL);rn return false;rn else rn return true;rn rn rn[/code]rn获取openid代码rn[code=java]rnprivate static final String APPID = "??";rn private static final String SECRET = "??";rn private static String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";rnrn @RequestMapping("/getOpenid")rn public String getOpenid(HttpServletRequest request, HttpServletResponse response) rn String path = (String) request.getSession().getAttribute("reqPath");rn rn // 用户同意授权后,能获取到codern String code = request.getParameter("code");rn rn // 获取网页授权access_tokenrn JSONObject object = getOauth2AccessToken(APPID, SECRET, code);rn rn request.getSession().setAttribute("openid", object.getString("openid"));rn return "redirect:" + path;rnrn rnrn public static JSONObject getOauth2AccessToken(String appId, String appSecret, String code) rn // 拼接请求地址rn requestUrl = requestUrl.replace("APPID", appId).replace("SECRET", appSecret).replace("CODE", code);rn // 获取网页授权凭证rn JSONObject jsonObject = null;rnrn try rn jsonObject = HttpUtil.getJsonForGet(requestUrl);rn catch (ParseException e) rn e.printStackTrace();rn catch (IOException e) rn e.printStackTrace();rn rnrn return jsonObject;rn rn[/code] 论坛

c++ 企业微信上传临时素材,提示errcode\":44001,\"errmsg\":\"empty media data

04-10

rn [code=c]int CHttpClient::ExecuteRequestUpload(LPCTSTR strFileName, LPCTSTR strUrl, string &strResponse) rn rn CString strServer; rn CString strObject; rn DWORD dwServiceType; rn INTERNET_PORT nPort; rn strResponse = ""; rn rn AfxParseURL(strUrl, dwServiceType, strServer, strObject, nPort); rn rn if(AFX_INET_SERVICE_HTTP != dwServiceType && AFX_INET_SERVICE_HTTPS != dwServiceType) rn rn return FAILURE; rn rn rn CFile fTrack; rn if (FALSE == fTrack.Open(strFileName, CFile::modeRead | CFile::shareDenyWrite)) rn return -1; rnrn CString strRequestHeader=_T(""); rn CString strHTTPBoundary=_T(""); rn CString strPreFileData=_T(""); rn CString strPostFileData=_T(""); rnrn DWORD dwTotalRequestLength = 0; rn DWORD dwChunkLength = 0; rn DWORD dwReadLength = 0; rn DWORD dwResponseLength = 0; rnrn LPSTR szResponse = NULL;rnrnrn CString strFilePath = strFileName;rn int startp = strFilePath.ReverseFind('\\'); rn int namelen = strFilePath.GetLength()-startp-1; rnrn CString szFileName = strFilePath.Mid(startp+1,namelen); rnrn strHTTPBoundary = _T("-----------------------------7d86d16250370"); rn strRequestHeader =MakeRequestHeaders(strHTTPBoundary,strServer,nPort); rn strPreFileData = MakePreFileData(strHTTPBoundary, szFileName,fTrack.GetLength()); rn strPostFileData = MakeRequestEnders(strHTTPBoundary); rnrn dwTotalRequestLength = strPreFileData.GetLength() + strPostFileData.GetLength() + fTrack.GetLength();rn dwChunkLength = 64 * 1024; rnrn void* pBuffer = malloc(dwChunkLength); rn if (NULL == pBuffer) rn rn return -1; rn rn elsern rn try rn rn m_pConnection = m_pSession->GetHttpConnection(strServer, rn dwServiceType == AFX_INET_SERVICE_HTTP ? NORMAL_CONNECT : SECURE_CONNECT, rn nPort); rn m_pFile = m_pConnection->OpenRequest("POST", strObject, rn NULL, 1, NULL, NULL, rn (dwServiceType == AFX_INET_SERVICE_HTTP ? NORMAL_REQUEST : SECURE_REQUEST)); rnrn m_pFile->AddRequestHeaders(strRequestHeader);rn m_pFile->SendRequestEx(dwTotalRequestLength, HSR_SYNC | HSR_INITIATE); rnrn#ifdef _UNICODE rn m_pFile->Write(W2A(strPreFileData), strPreFileData.GetLength()); rn#else rn m_pFile->Write((LPSTR)(LPCSTR)strPreFileData, strPreFileData.GetLength()); rn#endif rnrn dwReadLength = -1; rn while (0 != dwReadLength) rn rn dwReadLength = fTrack.Read(pBuffer, dwChunkLength); rn if (0 != dwReadLength) rn rn m_pFile->Write(pBuffer, dwReadLength); rn rn rnrn#ifdef _UNICODE rn m_pFile->Write(W2A(strPostFileData), strPostFileData.GetLength()); rn#else rn m_pFile->Write((LPSTR)(LPCSTR)strPostFileData, strPostFileData.GetLength()); rn#endif rnrn m_pFile->EndRequest(HSR_SYNC); rnrn dwResponseLength = m_pFile->GetLength(); rn while (0 != dwResponseLength) rn rn szResponse = (LPSTR)malloc(dwResponseLength + 1); rn szResponse[dwResponseLength] = '\0'; rn m_pFile->Read(szResponse, dwResponseLength); rn strResponse += szResponse; rn free(szResponse); rn dwResponseLength = m_pFile->GetLength(); rn rn rn catch (CInternetException* e) rn rn Clear(); rn DWORD dwErrorCode = e->m_dwError; rn e->Delete(); rnrn DWORD dwError = GetLastError(); rnrn if (ERROR_INTERNET_TIMEOUT == dwErrorCode) rn rn return OUTTIME; rn rn else rn rn return FAILURE; rn rn rn rnrn return SUCCESS; rn rnrnrnrn LPCTSTR CHttpClient::MakeRequestHeaders( LPCTSTR strBoundary, LPCTSTR strServerName, const int nPort)rn rn TCHAR strFormat[1024] = "";rn static TCHAR strData[1024];rnrn strcat(strFormat,"Accept-Language: zh-cn");rn strcat(strFormat,"Content-Type: multipart/form-data;boundary=%s\r\n");rn strcat(strFormat,"Connection: keep-alive\r\n");rn strcat(strFormat,"Host:%s\r\n");rnrn sprintf_s(strData,strFormat,strBoundary,strServerName);rnrn return strData;rn rnrn LPCTSTR CHttpClient::MakePreFileData( LPCTSTR strBoundary, LPCTSTR strFileName ,DWORD dsize)rn rn TCHAR strFormat[1024] = "";rn static TCHAR strData[1024];rnrn strcat(strFormat,"--%s\r\n");rn strcat(strFormat,"Content-Disposition: form-data; name=\"media\"; filename=\"%s\"\r\n");rn strcat(strFormat,"Content-Type:image/bmp;image/jpeg;image/x-png;application/zip\r\n");rn// strcat(strFormat,"Content-Transfer-Encoding:binary\r\n\r\n");rnrn sprintf_s(strData,strFormat,strBoundary,strFileName,dsize);rnrn return strData;rn rnrn LPCTSTR CHttpClient::MakeRequestEnders( LPCTSTR strBoundary )rn rn TCHAR strFormat[256] = "";rn static TCHAR strEnd[256];rnrn strcat(strFormat,"\r\n--%s\r\n");rn// strcat(strFormat,"Content-Disposition: form-data;name =\"submitted\"\r\n\r\n");rn// strcat(strFormat,"submit\r\n");rn// strcat(strFormat,"--%s--\r\n");rnrn sprintf_s(strEnd,strFormat,strBoundary);rn return strEnd;rn [/code] 论坛

微信开发实现多媒体上传时报"errcode":40014,"errmsg":"invalid access_token"

04-30

[code=java][/code]rnpublic static JSONObject uploadMedia3(String requestUrl,String mediaFileUrl) throws IOExceptionrn rn // 定义数据分割符 rn String boundary = "----------sunlight"; rn String result=null;rn File file=new File("f:\\13343648273775267406.jpg");rn if(!file.exists()||!file.isFile())rn throw new IOException("文件不存在");rn rn URL url=new URL(requestUrl);rn HttpURLConnection conn=(HttpURLConnection) url.openConnection();rn conn.setRequestMethod("POST");rn conn.setDoOutput(true);rn conn.setDoInput(true);rn conn.setUseCaches(false);rn //设置请求头信息rn conn.setRequestProperty("Connection", "keep-Alive");rn conn.setRequestProperty("Charset", "utf-8");rn //设置边界rn boundary=boundary+System.currentTimeMillis();rn conn.setRequestProperty("Content-Type","multipart/form-data;boundary="+boundary);rn //请求正文信息rn //第一部分:rn StringBuffer sb=new StringBuffer();rn sb.append("--");rn sb.append(boundary);rn sb.append("\r\n");rn sb.append("Content-Disposition:form-data;name=\"file\";filename=\""+file.getName()+"\"\r\n");rn sb.append("Content-Type:application/octet-stream\r\n\r\n");rn byte[] head=sb.toString().getBytes("utf-8");rn //获得输出流rn OutputStream out=new DataOutputStream(conn.getOutputStream());rn //输出表头rn out.write(head);rn //文件正文部分rn // 把文件已流文件的方式 推入到url中 rn DataInputStream in=new DataInputStream(new FileInputStream(file));rn int bytes=0;rn byte[] bufferOut=new byte[1024];rn while((bytes=in.read(bufferOut))!=-1)rn out.write(bufferOut,0,bytes);rn rn in.close();rn //结尾部分rn byte[] foot=("\r\n--"+boundary+"--\r\n").getBytes("utf-8");rn //定义最后数据分隔线rn out.write(foot);rn out.flush();rn out.close();rn StringBuffer buffer=new StringBuffer();rn BufferedReader reader=null;rn try rn // 定义BufferedReader输入流来读取URL的响应 rn reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));rn String line=null;rn while((line=reader.readLine())!=null)rn buffer.append(line);rn rn if(result==null)rn result=buffer.toString();rn rn catch (Exception e) rn System.out.println("发送POST请求出现异常!" + e);rn e.printStackTrace();rn throw new IOException("数据读取异常");rn finallyrn if(reader!=null)rn reader.close();rn rn rn System.out.println(result);rn JSONObject jsonObject=new JSONObject().fromObject(result);rn return jsonObject;rn 论坛

没有更多推荐了,返回首页