Foxtable(狐表)用户栏目专家坐堂 → 工资推送企业微信时遇到的问题


  共有2814人关注过本帖平板打印复制链接

主题:工资推送企业微信时遇到的问题

帅哥哟,离线,有人找我吗?
aidimeng
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:742 积分:7255 威望:0 精华:0 注册:2015/9/14 14:26:00
工资推送企业微信时遇到的问题  发帖心情 Post By:2020/12/14 15:57:00 [只看该作者]

参考论坛中的源码 在做相应的学习和测试
实现工资条推送到企业微信
下面是 推送微信的代码
Dim wzc As new List(of String)
Dim xms As new List(of String) '注册
For Each dr As Row In Tables("职工工资发放明细表").Rows
    Dim dt As DataRow = DataTables("员工花名册").SQLFind("身份证号 = '"& dr("身份证号") &"' And 微信权限 = 1 And 企业微信号ID <>''")
    If dt IsNot Nothing Then
     
        wzc.Add(dt("企业微信号id"))
        xms.add(dt("姓名"))
    End If
Next

Dim users As String
For Each userid As String In wzc
    users = users & "|" & userid
Next
Dim all As String = users.Remove(0,1)

Dim xm As String
For Each x As String In xms
    xm = xm & "|" & x
Next
Dim xinm As String = xm.Remove(0,1)
 
Dim tt As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim fy As WinForm.TextBox = e.Form.Controls("TextBox2")
Dim ur As String = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}"

Dim hc As new HttpClient(Cexp(ur,Functions.Execute("GetQYAccessToken2")))
 
Dim jo As New JObject
Dim ja As New JArray
jo("touser") =all
jo("msgtype") = "textcard"
Dim yyid As Integer = Vars("yyid")
jo("agentid") = yyid
jo("textcard") = New JObject
jo("textcard")("title") = tt.Text
jo("textcard")("description") = fy.Text
Dim yyzy As String = Vars("yyzy") &"/Remuneration/"
jo("textcard")("url") = yyzy
 
hc.Content = jo.ToString
jo = JObject.Parse(hc.GetData)

If jo("errcode") = "0" Then
    MessageBox.show("消息发送成功!,已将通知信息发送至:" & chr(13) & xinm)
Else
    MessageBox.show(jo.ToString)
End If

下面是服务端的代码

Dim fl As String = "d:\web\" & e.Path
If filesys.FileExists(fl)
    Dim idx As Integer = fl.LastIndexOf(".")
    Dim ext As String  = fl.SubString(idx)
    Select Case ext
        Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar"
            e.WriteFile(fl)
            Return '这里必须返回
    End Select
End If
  
 
Select Case e.path
    Case "Remuneration"  '工资信息

        '       Dim e As RequestEventArgs = args(0)
        Dim UserId As String
        Dim UserName As String
        Dim sb As New StringBuilder
        sb.AppendLine("<meta name='viewport' c>")
        If e.GetValues.ContainsKey("code") Then '如果通过授权链接跳转而来,就根据传递过来的code参数调用接口,获取用户的UserId
            'MessageBox.Show("通过授权链接进入")
            Dim ul As String  = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={0}&code={1}"
            ul = CExp(ul,Functions.Execute("GetQYAccessToken"),e.GetValues("code"))
            Dim hc As new HttpClient(ul)
            Dim jo As JObject = JObject.Parse(hc.GetData)
            If jo("UserId") IsNot Nothing Then
                UserId = jo("UserId")
Else
MessageBox.Show("meiyou")
                'MessageBox.Show("通过授权链接包含信息:" & userid)
            End If
        Else
            UserId = e.Cookies("userid") '否则从cookie中提取userid
            'MessageBox.Show("通过cookies获取:" & userid)
        End If
        Dim Verified As Boolean
        Dim drc As DataRow = DataTables("员工花名册").SQLFind("企业微信号ID ='" & UserId & "'") '根据openid找出对应的行
        If UserId  > "" AndAlso drc IsNot Nothing  AndAlso drc("微信权限") = True '授权成功
            Verified  = True
            UserName = drc("姓名")
            e.AppendCookie("userid",UserId) '将userid和username存储在Cookie中
            
        ElseIf e.GetValues.ContainsKey("code") = False Then '如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
            'MessageBox.Show("跳转授权链接" & userid)
            Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&agentid={2}&state=STATE#wechat_redirect"
            Dim ul2 As String = UrlEncode(Vars("yyzy"))
            ul = CExp(ul,Vars("qyid"),ul2,Vars("yyid"))
            'Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww8bbc1c6c7bd8a2e7&redirect_uri=http%3a%2f%2fgz.crucg.top%3a8090%2fRemuneration&response_type=code&scope=snsapi_base&agentid=1000002&state=STATE#wechat_redirect"
            sb.Append("<meta http-equiv='Refresh' c>") '跳转到授权链接%3a8090
            e.WriteString(sb.ToString)
            Return
        End If
        If Verified = False Then
            'MessageBox.Show("授权不通过:" & userid)
            sb.AppendLine("你无权访问本系统")
        Else
            'MessageBox.Show("通过,进入主页")
            'MessageBox.Show("授权成功")
            e.WriteString("<meta http-equiv='Refresh' c>")
            '    sb.AppendLine("欢迎" & UserName & "同志使用本系统,授权成功!请" & " , <a href='http://www.crucg.top/Remuneration2'>刷新页面后进去</a>")
        End If
        e.WriteString(sb.ToString)
        
    Case "Remuneration2"
        If e.Cookies.ContainsKey("userid") =False Then
            e.WriteString("非法访问")
            Return
        End If
        e.AsyncExecute = True
        Functions.AsyncExecute("Remuneration2",e)
    Case "mx"
        If e.Cookies.ContainsKey("userid") =False Then
            e.WriteString("非法访问")
            Return
        End If
        e.AsyncExecute = True
        Functions.AsyncExecute("mx",e)
    Case "order.xls"
        If e.Cookies.ContainsKey("userid") =False Then
            e.WriteString("非法访问")
            Return
        End If
        e.AsyncExecute = True
        Functions.AsyncExecute("CreateXLS",e)
    Case "tongji"
        If e.Cookies.ContainsKey("userid") =False Then
            e.WriteString("非法访问")
            Return
        End If
        e.AsyncExecute = True
        Functions.AsyncExecute("tongji",e)
    Case "tongjit"
        If e.Cookies.ContainsKey("userid") =False Then
            e.WriteString("非法访问")
            Return
        End If
        e.AsyncExecute = True
        Functions.AsyncExecute("tongjit",e)
End S elect

可以成功推送到企业微信,但点开推送消息 总是空白页面,地址是
http://admgz.yogi.com.cn:3333/?code=BZCV6ZOzC9Uu9ksI7oG2KhPfl1NV8cltbEX9JWC5j0Q&state=STATE

我已经把admgz.yogi.com.cn:3333 设置成了可信域名
实在不理解 为什么 推送后 打开的页面是空白的,好像是少了个 参数




 回到顶部
总数 20 1 2 下一页