楼上是api ticket的问题,解决了
下面是新的小问题
Dim nianyue As String = Format(Date.Today, "yyyyMM") '定义,年月
Dim NewName As String = Format(Date.Now, "yyyyMMddHHmmss") & Rand.Next(10000,99999)
Dim fl As String = "e:\web\daod\" & nianyue & "\" & NewName & ".jpg" '要保存为的本地文件
Dim sucess As Boolean = True '用于标记是否下载成功
Dim url As String = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}"
Dim mediaID As String = serverId '"qINAMviNpYpn5EcMwb2EmrsoCR6zUo8rJQplei1uyluhfbSVZ_esSva9NkuU8W1m" '要下载的素材ID
url = CExp(url, AccessToken, mediaID)
Dim hc As New HttpClient(url)
If hc.GetFile(fl) Then
If hc.ResponseContentType.StartsWith("text/plain") Then
Dim jo As JObject = JObject.Parse(Filesys.ReadAllText(fl))
MessageBox.Show(jo.ToString) '显示错误信息
Functions.Execute("LogText","下载验证男生到达图片错误" & jo.ToString)
FileSys.DeleteFile(fl) '删除文件
sucess = False
Else
If hc.ResponseContentType.contains("jpeg") Then
Functions.Execute("LogText","下载验证男生到达图片,转换格式,记录f1=" & fl)
msgbox(1) ’1显示了
FileSys.RenameFile(fl, FileSys.GetName(fl).replace(".jpeg", ".jpg"))
msgbox(2) ’2没有显示
ElseIf hc.ResponseContentType.contains("gif") OrElse hc.ResponseContentType.contains("png") OrElse hc.ResponseContentType.contains("bmp") OrElse hc.ResponseContentType.contains("wmf") Then
FileSys.DeleteFile(fl) '删除文件
Functions.Execute("LogText","下载验证男生到达图片,格式错误,记录f1=" & fl)
e.WriteString("验证照片格式错误!")
Return ""
End If
End If
Else
sucess = False
End If
服务器记录:
2018-12-08 11:11:08.8457
下载验证男生到达图片,转换格式,记录f1=e:\web\daod\201812\2018120811110851638.jpg
2018-12-08 11:11:16.1507
调用的目标发生了异常。
在 System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
在 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
在 Foxtable.UserFunctions.Execute(String Name, Object[] Args)
未能完成操作,因为此路径“e:\web\daod\201812\2018120811110851638.jpg”中已存在文件。
在 Microsoft.VisualBasic.FileIO.FileSystem.EnsurePathNotExist(String Path)
在 Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(String file, String newName)
在 Microsoft.VisualBasic.MyServices.FileSystemProxy.RenameFile(String file, String newName)
在 UserCode.As3gQwU2XqdnlVJbl(Object[] Args)
[此贴子已经被作者于2018/12/8 11:22:39编辑过]