Example #1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            string proxyHost     = this.tProxyHost.Text;
            string proxyPort     = this.tProxyPort.Text;
            string proxyName     = this.tProxyName.Text;
            string proxyPassword = this.tProxyPassword.Text;

            string corpId     = this.tCorpId.Text;
            string corpSecret = this.tCorpSecret.Text;

            try {
                //RequestUtility.SetHttpProxy(proxyHost, proxyPort, proxyName, proxyPassword);
                string token = AccessTokenContainer.TryGetToken(corpId, corpSecret);

                //上传图片
                if (!string.IsNullOrWhiteSpace(this.tPicPath.Text))
                {
                    if (!File.Exists(this.tPicPath.Text))
                    {
                        this.tRtnMsg.Text = "图片路径不存在!";
                        return;
                    }
                    else
                    {
                        string media        = string.Format("Content-Disposition:form-data;name=\"file\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", this.tPicPath.Text);
                        var    uploadResult = MediaApi.UploadimgMedia(token, media);
                        this.tUploadPicUrl.Text = uploadResult.url;
                    }
                }

                var sendNewsUrl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}";
                var result      = CommonJsonSend.Send(token, sendNewsUrl, ConstructNewsData());
                this.tRtnMsg.Text = result.errcode + "  " + result.errmsg;
            }
            catch (Exception ex)
            {
                this.tRtnMsg.Text = ex.Message;
            }
        }
Example #2
0
        /// <summary>
        /// 上传图片到微信服务器,但是返回url;
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public UploadimgMediaResult UploadimgMedia(string filepath)
        {
            var result = MediaApi.UploadimgMedia(AccessTokenOrAppKey, filepath);

            return(result);
        }